Region capture functionality now working same as before with new shape system

This commit is contained in:
Jaex 2016-05-03 12:35:10 +03:00
parent 43843cefc7
commit 1672ee3f5c
7 changed files with 162 additions and 112 deletions

View file

@ -138,13 +138,15 @@ public enum FFmpegPaletteUseDither
sierra2_4a
}
public enum RegionShape
public enum ShapeType
{
Rectangle,
RoundedRectangle,
Ellipse,
Triangle,
Diamond
RegionRectangle,
RegionRoundedRectangle,
RegionEllipse,
RegionTriangle,
RegionDiamond,
DrawingRectangle,
DrawingRoundedRectangle
}
public enum RegionAnnotateMode

View file

@ -215,12 +215,13 @@ protected override void Draw(Graphics g)
}
}
List<BaseRegionShape> areas = AreaManager.ValidRegions.ToList();
List<BaseShape> areas = AreaManager.ValidRegions.ToList();
bool drawAreaExist = areas.Count > 0;
if (AreaManager.IsCurrentHoverAreaValid && areas.All(area => area.Rectangle != AreaManager.CurrentHoverRectangle))
{
areas.Add(AreaManager.GetRegionInfo(AreaManager.CurrentHoverRectangle));
BaseShape shape = AreaManager.CreateRegionShape(AreaManager.CurrentHoverRectangle);
areas.Add(shape);
}
if (areas.Count > 0)
@ -263,7 +264,7 @@ protected override void Draw(Graphics g)
{
using (GraphicsPath hoverDrawPath = new GraphicsPath { FillMode = FillMode.Winding })
{
AreaManager.GetRegionInfo(AreaManager.CurrentHoverRectangle).AddShapePath(hoverDrawPath, -1);
AreaManager.CreateRegionShape(AreaManager.CurrentHoverRectangle).AddShapePath(hoverDrawPath, -1);
g.DrawPath(borderPen, hoverDrawPath);
g.DrawPath(borderDotPen, hoverDrawPath);
@ -457,26 +458,26 @@ protected virtual void WriteTips(StringBuilder sb)
sb.AppendLine();
/*if (Config.CurrentRegionShape == RegionShape.Rectangle) sb.Append("-> ");
if (AreaManager.CurrentShapeType == ShapeType.RegionRectangle) sb.Append("-> ");
sb.AppendLine(Resources.RectangleRegion_WriteTips__Numpad_1__Rectangle_shape);
if (Config.CurrentRegionShape == RegionShape.RoundedRectangle) sb.Append("-> ");
if (AreaManager.CurrentShapeType == ShapeType.RegionRoundedRectangle) sb.Append("-> ");
sb.AppendLine(Resources.RectangleRegion_WriteTips__Numpad_2__Rounded_rectangle_shape);
if (Config.CurrentRegionShape == RegionShape.Ellipse) sb.Append("-> ");
if (AreaManager.CurrentShapeType == ShapeType.RegionEllipse) sb.Append("-> ");
sb.AppendLine(Resources.RectangleRegion_WriteTips__Numpad_3__Ellipse_shape);
if (Config.CurrentRegionShape == RegionShape.Triangle) sb.Append("-> ");
if (AreaManager.CurrentShapeType == ShapeType.RegionTriangle) sb.Append("-> ");
sb.AppendLine(Resources.RectangleRegion_WriteTips__Numpad_4__Triangle_shape);
if (Config.CurrentRegionShape == RegionShape.Diamond) sb.Append("-> ");
if (AreaManager.CurrentShapeType == ShapeType.RegionDiamond) sb.Append("-> ");
sb.AppendLine(Resources.RectangleRegion_WriteTips__Numpad_5__Diamond_shape);
switch (Config.CurrentRegionShape)
switch (AreaManager.CurrentShapeType)
{
case RegionShape.RoundedRectangle:
case ShapeType.RegionRoundedRectangle:
sb.AppendLine(Resources.RectangleRegion_WriteTips__Numpad___or____Change_rounded_rectangle_corner_radius);
break;
case RegionShape.Triangle:
case ShapeType.RegionTriangle:
sb.AppendLine(Resources.RectangleRegion_WriteTips__Numpad___or____Change_triangle_angle);
break;
}*/
}
}
private string GetAreaText(Rectangle area)
@ -706,7 +707,7 @@ public void UpdateRegionPath()
foreach (BaseRegionShape regionShape in AreaManager.ValidRegions)
{
regionShape.AddShapePath(regionFillPath);
regionShape.AddShapePath(regionFillPath, -1);
regionShape.AddShapePath(regionDrawPath, -1);
}
}
}

View file

@ -38,6 +38,8 @@ public class AreaManager
public BaseShape CurrentShape { get; private set; }
public ShapeType CurrentShapeType { get; set; } = ShapeType.RegionRectangle;
public Rectangle CurrentRectangle
{
get
@ -58,7 +60,7 @@ public Rectangle CurrentRectangle
}
}
public BaseRegionShape[] Regions
public BaseShape[] Regions
{
get
{
@ -66,7 +68,7 @@ public BaseRegionShape[] Regions
}
}
public BaseRegionShape[] ValidRegions
public BaseShape[] ValidRegions
{
get
{
@ -167,27 +169,31 @@ private void surface_KeyDown(object sender, KeyEventArgs e)
IsSnapResizing = true;
break;
case Keys.NumPad1:
//ChangeCurrentShape(RegionShape.Rectangle);
CurrentShapeType = ShapeType.RegionRectangle;
break;
case Keys.NumPad2:
//ChangeCurrentShape(RegionShape.RoundedRectangle);
CurrentShapeType = ShapeType.RegionRoundedRectangle;
break;
case Keys.NumPad3:
//ChangeCurrentShape(RegionShape.Ellipse);
CurrentShapeType = ShapeType.RegionEllipse;
break;
case Keys.NumPad4:
//ChangeCurrentShape(RegionShape.Triangle);
CurrentShapeType = ShapeType.RegionTriangle;
break;
case Keys.NumPad5:
//ChangeCurrentShape(RegionShape.Diamond);
CurrentShapeType = ShapeType.RegionDiamond;
break;
/*case Keys.Add:
switch (surface.Config.CurrentRegionShape)
case Keys.NumPad0:
CurrentShapeType = ShapeType.DrawingRectangle;
break;
case Keys.Add:
switch (CurrentShapeType)
{
case RegionShape.RoundedRectangle:
case ShapeType.RegionRoundedRectangle:
RoundedRectangleRadius += RoundedRectangleRadiusIncrement;
UpdateRoundedRectangle();
break;
case RegionShape.Triangle:
case ShapeType.RegionTriangle:
if (TriangleAngle == TriangleAngle.Left)
{
TriangleAngle = TriangleAngle.Top;
@ -196,17 +202,18 @@ private void surface_KeyDown(object sender, KeyEventArgs e)
{
TriangleAngle++;
}
UpdateTriangle();
break;
}
UpdateCurrentRegionInfo();
break;
case Keys.Subtract:
switch (surface.Config.CurrentRegionShape)
switch (CurrentShapeType)
{
case RegionShape.RoundedRectangle:
case ShapeType.RegionRoundedRectangle:
RoundedRectangleRadius = Math.Max(0, RoundedRectangleRadius - RoundedRectangleRadiusIncrement);
UpdateRoundedRectangle();
break;
case RegionShape.Triangle:
case ShapeType.RegionTriangle:
if (TriangleAngle == TriangleAngle.Top)
{
TriangleAngle = TriangleAngle.Left;
@ -215,10 +222,36 @@ private void surface_KeyDown(object sender, KeyEventArgs e)
{
TriangleAngle--;
}
UpdateTriangle();
break;
}
UpdateCurrentRegionInfo();
break;*/
break;
}
}
private void UpdateRoundedRectangle()
{
if (CurrentShape != null)
{
RoundedRectangleRegionShape roundedRectangleShape = CurrentShape as RoundedRectangleRegionShape;
if (roundedRectangleShape != null)
{
roundedRectangleShape.Radius = RoundedRectangleRadius;
}
}
}
private void UpdateTriangle()
{
if (CurrentShape != null)
{
TriangleRegionShape triangleShape = CurrentShape as TriangleRegionShape;
if (triangleShape != null)
{
triangleShape.Angle = TriangleAngle;
}
}
}
@ -415,7 +448,7 @@ private void RegionSelection(Point location)
rect = new Rectangle(location, new Size(1, 1));
}
AddRegionInfo(rect);
AddRegionShape(rect);
}
}
@ -444,7 +477,7 @@ private void EndRegionSelection()
if (!CurrentHoverRectangle.IsEmpty)
{
AddRegionInfo(CurrentHoverRectangle);
AddRegionShape(CurrentHoverRectangle);
if (surface.Config.QuickCrop)
{
@ -473,40 +506,52 @@ private void CancelRegionSelection()
}
}
private void ChangeCurrentShape(BaseShape shape)
private void AddRegionShape(Rectangle rect)
{
surface.Config.CurrentRegionShape = shape;
UpdateCurrentRegionInfo();
BaseShape shape = CreateRegionShape(rect);
Shapes.Add(shape);
CurrentShape = shape;
}
private void AddRegionInfo(Rectangle rect)
public BaseShape CreateRegionShape(Rectangle rect)
{
Shapes.Add(GetRegionInfo(rect));
CurrentShape = Shapes[Shapes.Count - 1];
}
BaseShape shape;
public BaseRegionShape GetRegionInfo(Rectangle rect)
switch (CurrentShapeType)
{
BaseRegionShape regionInfo = new RectangleRegionShape()
default:
case ShapeType.RegionRectangle:
shape = new RectangleRegionShape();
break;
case ShapeType.RegionRoundedRectangle:
shape = new RoundedRectangleRegionShape()
{
Rectangle = rect
Radius = RoundedRectangleRadius
};
//surface.Config.CurrentRegionShape
//regionInfo.RoundedRectangleRadius = RoundedRectangleRadius;
//regionInfo.TriangleAngle = TriangleAngle;
return regionInfo;
break;
case ShapeType.RegionEllipse:
shape = new EllipseRegionShape();
break;
case ShapeType.RegionTriangle:
shape = new TriangleRegionShape()
{
Angle = TriangleAngle
};
break;
case ShapeType.RegionDiamond:
shape = new DiamondRegionShape();
break;
case ShapeType.DrawingRectangle:
shape = new RectangleDrawingShape();
break;
case ShapeType.DrawingRoundedRectangle:
shape = new RoundedRectangleDrawingShape();
break;
}
private void UpdateCurrentRegionInfo()
{
BaseShape regionInfo = CurrentShape;
shape.Rectangle = rect;
if (regionInfo != null)
{
/*regionInfo.Shape = surface.Config.CurrentRegionShape;
regionInfo.RoundedRectangleRadius = RoundedRectangleRadius;
regionInfo.TriangleAngle = TriangleAngle;*/
}
return shape;
}
private void SelectArea()

View file

@ -23,7 +23,9 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace ShareX.ScreenCaptureLib
{
@ -39,5 +41,21 @@ public BaseShape(Rectangle rect)
{
Rectangle = rect;
}
public virtual void AddShapePath(GraphicsPath gp, Rectangle rect)
{
gp.AddRectangle(rect);
}
public void AddShapePath(GraphicsPath gp)
{
AddShapePath(gp, Rectangle);
}
public void AddShapePath(GraphicsPath gp, int sizeOffset)
{
Rectangle rect = Rectangle.SizeOffset(sizeOffset);
AddShapePath(gp, rect);
}
}
}

View file

@ -33,19 +33,7 @@ You should have received a copy of the GNU General Public License
namespace ShareX.ScreenCaptureLib
{
public abstract class BaseRegionShape : BaseShape
public class BaseRegionShape : BaseShape
{
public abstract void AddShapePath(GraphicsPath gp, Rectangle rect);
public void AddShapePath(GraphicsPath gp)
{
AddShapePath(gp, Rectangle);
}
public void AddShapePath(GraphicsPath gp, int sizeOffset)
{
Rectangle rect = Rectangle.SizeOffset(sizeOffset);
AddShapePath(gp, rect);
}
}
}

View file

@ -34,9 +34,5 @@ namespace ShareX.ScreenCaptureLib
{
public class RectangleRegionShape : BaseRegionShape
{
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
{
gp.AddRectangle(rect);
}
}
}

View file

@ -98,8 +98,8 @@ public class SurfaceOptions
[Description("How close to a snap size you must be for it to snap.")]
public List<SnapSize> SnapSizes { get; set; }
[Description("Current region shape.")]
public BaseShape CurrentRegionShape { get; set; } = new RectangleRegionShape();
[DefaultValue(ShapeType.RegionRectangle), Description("Current region shape.")]
public ShapeType CurrentShapeType { get; set; } = ShapeType.RegionRectangle;
public SurfaceOptions()
{