Each region have its own angle and radius info and changeable in selected region

This commit is contained in:
Jaex 2015-07-16 22:07:06 +03:00
parent bddbb2b136
commit 5b9cf79f48
10 changed files with 126 additions and 342 deletions

View file

@ -1,39 +0,0 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright © 2007-2015 ShareX Developers
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 ShareX.HelpersLib;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace ShareX.ScreenCaptureLib
{
public class DiamondRegion : RectangleRegion
{
protected override void AddShapePath(GraphicsPath graphicsPath, Rectangle rect, RegionShape shape)
{
graphicsPath.AddDiamond(rect);
}
}
}

View file

@ -1,38 +0,0 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright © 2007-2015 ShareX Developers
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.Drawing;
using System.Drawing.Drawing2D;
namespace ShareX.ScreenCaptureLib
{
public class EllipseRegion : RectangleRegion
{
protected override void AddShapePath(GraphicsPath graphicsPath, Rectangle rect, RegionShape shape)
{
graphicsPath.AddEllipse(rect);
}
}
}

View file

@ -38,10 +38,6 @@ public class RectangleRegion : Surface
{
public AreaManager AreaManager { get; private set; }
public float RoundedRectangleRadius { get; set; }
public int RoundedRectangleRadiusIncrement { get; set; }
public TriangleAngle TriangleAngle { get; set; }
#region Screen color picker
public bool ScreenColorPickerMode { get; set; }
@ -77,10 +73,6 @@ public RectangleRegion()
{
AreaManager = new AreaManager(this);
RoundedRectangleRadius = 25;
RoundedRectangleRadiusIncrement = 3;
TriangleAngle = TriangleAngle.Top;
KeyDown += RectangleRegion_KeyDown;
MouseDown += RectangleRegion_MouseDown;
MouseWheel += RectangleRegion_MouseWheel;
@ -114,57 +106,6 @@ private void RectangleRegion_KeyDown(object sender, KeyEventArgs e)
case Keys.Control | Keys.C:
CopyAreaInfo();
break;
case Keys.NumPad1:
AreaManager.CurrentShape = RegionShape.Rectangle;
break;
case Keys.NumPad2:
AreaManager.CurrentShape = RegionShape.RoundedRectangle;
break;
case Keys.NumPad3:
AreaManager.CurrentShape = RegionShape.Ellipse;
break;
case Keys.NumPad4:
AreaManager.CurrentShape = RegionShape.Triangle;
break;
case Keys.NumPad5:
AreaManager.CurrentShape = RegionShape.Diamond;
break;
case Keys.Add:
switch (AreaManager.CurrentShape)
{
case RegionShape.RoundedRectangle:
RoundedRectangleRadius += RoundedRectangleRadiusIncrement;
break;
case RegionShape.Triangle:
if (TriangleAngle == TriangleAngle.Left)
{
TriangleAngle = TriangleAngle.Top;
}
else
{
TriangleAngle++;
}
break;
}
break;
case Keys.Subtract:
switch (AreaManager.CurrentShape)
{
case RegionShape.RoundedRectangle:
RoundedRectangleRadius = Math.Max(0, RoundedRectangleRadius - RoundedRectangleRadiusIncrement);
break;
case RegionShape.Triangle:
if (TriangleAngle == TriangleAngle.Top)
{
TriangleAngle = TriangleAngle.Left;
}
else
{
TriangleAngle--;
}
break;
}
break;
}
}
@ -288,7 +229,7 @@ protected override void Draw(Graphics g)
{
using (GraphicsPath hoverDrawPath = new GraphicsPath { FillMode = FillMode.Winding })
{
AddShapePath(hoverDrawPath, AreaManager.CurrentHoverArea.SizeOffset(-1), AreaManager.CurrentShape);
AddShapePath(hoverDrawPath, AreaManager.GetRegionInfo(AreaManager.CurrentHoverArea), -1);
g.DrawPath(borderPen, hoverDrawPath);
g.DrawPath(borderDotPen, hoverDrawPath);
@ -679,30 +620,32 @@ public void UpdateRegionPath()
foreach (RegionInfo regionInfo in AreaManager.ValidAreas)
{
AddShapePath(regionFillPath, regionInfo.Area, regionInfo.Shape);
AddShapePath(regionDrawPath, regionInfo.Area.SizeOffset(-1), regionInfo.Shape);
AddShapePath(regionFillPath, regionInfo);
AddShapePath(regionDrawPath, regionInfo, -1);
}
}
protected virtual void AddShapePath(GraphicsPath graphicsPath, Rectangle rect, RegionShape shape)
protected virtual void AddShapePath(GraphicsPath graphicsPath, RegionInfo regionInfo, int sizeOffset = 0)
{
switch (shape)
Rectangle area = regionInfo.Area.SizeOffset(sizeOffset);
switch (regionInfo.Shape)
{
default:
case RegionShape.Rectangle:
graphicsPath.AddRectangle(rect);
graphicsPath.AddRectangle(area);
break;
case RegionShape.RoundedRectangle:
graphicsPath.AddRoundedRectangle(rect, RoundedRectangleRadius);
graphicsPath.AddRoundedRectangle(area, regionInfo.RoundedRectangleRadius);
break;
case RegionShape.Ellipse:
graphicsPath.AddEllipse(rect);
graphicsPath.AddEllipse(area);
break;
case RegionShape.Triangle:
graphicsPath.AddTriangle(rect, TriangleAngle);
graphicsPath.AddTriangle(area, regionInfo.TriangleAngle);
break;
case RegionShape.Diamond:
graphicsPath.AddDiamond(rect);
graphicsPath.AddDiamond(area);
break;
}
}

View file

@ -1,71 +0,0 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright © 2007-2015 ShareX Developers
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 ShareX.HelpersLib;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
public class RoundedRectangleRegion : RectangleRegion
{
public float Radius { get; set; }
public int RadiusIncrement { get; set; }
public RoundedRectangleRegion()
{
Radius = 25;
RadiusIncrement = 3;
KeyDown += RoundedRectangleRegion_KeyDown;
}
private void RoundedRectangleRegion_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Add)
{
Radius += RadiusIncrement;
}
else if (e.KeyData == Keys.Subtract)
{
Radius = Math.Max(0, Radius - RadiusIncrement);
}
}
protected override void AddShapePath(GraphicsPath graphicsPath, Rectangle rect, RegionShape shape)
{
graphicsPath.AddRoundedRectangle(rect, Radius);
}
protected override void WriteTips(StringBuilder sb)
{
base.WriteTips(sb);
sb.AppendLine("[Numpad +] [Numpad -] Change corner radius");
}
}
}

View file

@ -1,82 +0,0 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright © 2007-2015 ShareX Developers
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 ShareX.HelpersLib;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
public class TriangleRegion : RectangleRegion
{
public TriangleAngle Angle { get; set; }
public TriangleRegion()
{
Angle = TriangleAngle.Top;
KeyDown += TriangleRegion_KeyDown;
}
private void TriangleRegion_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Add)
{
if (Angle == TriangleAngle.Left)
{
Angle = TriangleAngle.Top;
}
else
{
Angle++;
}
}
else if (e.KeyData == Keys.Subtract)
{
if (Angle == TriangleAngle.Top)
{
Angle = TriangleAngle.Left;
}
else
{
Angle--;
}
}
}
protected override void AddShapePath(GraphicsPath graphicsPath, Rectangle rect, RegionShape shape)
{
graphicsPath.AddTriangle(rect, Angle);
}
protected override void WriteTips(StringBuilder sb)
{
base.WriteTips(sb);
sb.AppendLine("[Numpad +] [Numpad -] Change triangle angle");
}
}
}

View file

@ -24,6 +24,7 @@
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
@ -33,8 +34,6 @@ namespace ShareX.ScreenCaptureLib
{
public class AreaManager
{
public RegionShape CurrentShape { get; set; }
public List<RegionInfo> Areas { get; private set; }
public RegionInfo[] ValidAreas
@ -47,6 +46,19 @@ public RegionInfo[] ValidAreas
public int SelectedAreaIndex { get; private set; }
public RegionInfo CurrentRegionInfo
{
get
{
if (SelectedAreaIndex > -1)
{
return Areas[SelectedAreaIndex];
}
return null;
}
}
public Rectangle CurrentArea
{
get
@ -85,6 +97,11 @@ public bool IsCurrentHoverAreaValid
}
}
public RegionShape CurrentShape { get; set; }
public float RoundedRectangleRadius { get; set; }
public int RoundedRectangleRadiusIncrement { get; set; }
public TriangleAngle TriangleAngle { get; set; }
public ResizeManager ResizeManager { get; private set; }
public bool IsCreating { get; private set; }
public bool IsMoving { get; private set; }
@ -112,9 +129,12 @@ public AreaManager(RectangleRegion surface)
this.surface = surface;
ResizeManager = new ResizeManager(surface, this);
CurrentShape = RegionShape.Rectangle;
Areas = new List<RegionInfo>();
SelectedAreaIndex = -1;
CurrentShape = RegionShape.Rectangle;
RoundedRectangleRadius = 25;
RoundedRectangleRadiusIncrement = 3;
TriangleAngle = TriangleAngle.Top;
MinimumSize = 10;
surface.MouseDown += surface_MouseDown;
@ -125,9 +145,64 @@ public AreaManager(RectangleRegion surface)
private void surface_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.ShiftKey)
switch (e.KeyData)
{
proportionalResizing = true;
case Keys.ShiftKey:
proportionalResizing = true;
break;
case Keys.NumPad1:
ChangeCurrentShape(RegionShape.Rectangle);
break;
case Keys.NumPad2:
ChangeCurrentShape(RegionShape.RoundedRectangle);
break;
case Keys.NumPad3:
ChangeCurrentShape(RegionShape.Ellipse);
break;
case Keys.NumPad4:
ChangeCurrentShape(RegionShape.Triangle);
break;
case Keys.NumPad5:
ChangeCurrentShape(RegionShape.Diamond);
break;
case Keys.Add:
switch (CurrentShape)
{
case RegionShape.RoundedRectangle:
RoundedRectangleRadius += RoundedRectangleRadiusIncrement;
break;
case RegionShape.Triangle:
if (TriangleAngle == TriangleAngle.Left)
{
TriangleAngle = TriangleAngle.Top;
}
else
{
TriangleAngle++;
}
break;
}
UpdateCurrentRegionInfo();
break;
case Keys.Subtract:
switch (CurrentShape)
{
case RegionShape.RoundedRectangle:
RoundedRectangleRadius = Math.Max(0, RoundedRectangleRadius - RoundedRectangleRadiusIncrement);
break;
case RegionShape.Triangle:
if (TriangleAngle == TriangleAngle.Top)
{
TriangleAngle = TriangleAngle.Left;
}
else
{
TriangleAngle--;
}
break;
}
UpdateCurrentRegionInfo();
break;
}
}
@ -229,8 +304,7 @@ private void surface_MouseDown(object sender, MouseEventArgs e)
rect = new Rectangle(e.Location, new Size(1, 1));
}
Areas.Add(new RegionInfo(rect, CurrentShape));
SelectedAreaIndex = Areas.Count - 1;
AddRegionInfo(rect);
}
}
}
@ -262,8 +336,7 @@ private void surface_MouseUp(object sender, MouseEventArgs e)
if (!CurrentHoverArea.IsEmpty)
{
Areas.Add(new RegionInfo(CurrentHoverArea, CurrentShape));
SelectedAreaIndex = Areas.Count - 1;
AddRegionInfo(CurrentHoverArea);
if (surface.Config.QuickCrop)
{
@ -292,6 +365,34 @@ private void surface_MouseUp(object sender, MouseEventArgs e)
}
}
private void ChangeCurrentShape(RegionShape shape)
{
CurrentShape = shape;
UpdateCurrentRegionInfo();
}
private void AddRegionInfo(Rectangle rect)
{
Areas.Add(GetRegionInfo(rect));
SelectedAreaIndex = Areas.Count - 1;
}
public RegionInfo GetRegionInfo(Rectangle rect)
{
RegionInfo regionInfo = new RegionInfo(rect, CurrentShape);
regionInfo.RoundedRectangleRadius = RoundedRectangleRadius;
regionInfo.TriangleAngle = TriangleAngle;
return regionInfo;
}
private void UpdateCurrentRegionInfo()
{
RegionInfo regionInfo = CurrentRegionInfo;
regionInfo.Shape = CurrentShape;
regionInfo.RoundedRectangleRadius = RoundedRectangleRadius;
regionInfo.TriangleAngle = TriangleAngle;
}
private void SelectArea()
{
if (!CurrentArea.IsEmpty && !surface.Config.IsFixedSize)

View file

@ -23,6 +23,7 @@
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System;
using System.Collections.Generic;
using System.Drawing;
@ -35,6 +36,8 @@ public class RegionInfo
{
public Rectangle Area { get; set; }
public RegionShape Shape { get; set; }
public float RoundedRectangleRadius { get; set; }
public TriangleAngle TriangleAngle { get; set; }
public RegionInfo(Rectangle area, RegionShape shape)
{

View file

@ -83,12 +83,6 @@
</Compile>
<Compile Include="RegionHelpers\AreaManager.cs" />
<Compile Include="RegionHelpers\DrawObject.cs" />
<Compile Include="Forms\DiamondRegion.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\EllipseRegion.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\FreeHandRegion.cs">
<SubType>Form</SubType>
</Compile>
@ -98,12 +92,6 @@
<Compile Include="Forms\RectangleRegion.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\RoundedRectangleRegion.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\TriangleRegion.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="RegionHelpers\InputManager.cs" />
<Compile Include="RegionHelpers\MouseState.cs" />
<Compile Include="RegionHelpers\NodeObject.cs" />

View file

@ -120,10 +120,6 @@ public enum CaptureType
ActiveWindow,
RectangleWindow,
Rectangle,
RoundedRectangle,
Ellipse,
Triangle,
Diamond,
Polygon,
Freehand,
CustomRegion,

View file

@ -1660,10 +1660,6 @@ public void CaptureScreenshot(CaptureType captureType, TaskSettings taskSettings
break;
case CaptureType.Rectangle:
case CaptureType.RectangleWindow:
case CaptureType.RoundedRectangle:
case CaptureType.Ellipse:
case CaptureType.Triangle:
case CaptureType.Diamond:
case CaptureType.Polygon:
case CaptureType.Freehand:
CaptureRegion(captureType, taskSettings, autoHideForm);
@ -1757,8 +1753,7 @@ private void AfterCapture(Image img, CaptureType captureType, TaskSettings taskS
private bool IsRegionCapture(CaptureType captureType)
{
return captureType.HasFlagAny(CaptureType.RectangleWindow, CaptureType.Rectangle, CaptureType.RoundedRectangle, CaptureType.Ellipse,
CaptureType.Triangle, CaptureType.Diamond, CaptureType.Polygon, CaptureType.Freehand, CaptureType.LastRegion);
return captureType.HasFlagAny(CaptureType.RectangleWindow, CaptureType.Rectangle, CaptureType.Polygon, CaptureType.Freehand, CaptureType.LastRegion);
}
private void CaptureActiveWindow(TaskSettings taskSettings, bool autoHideForm = true)
@ -1848,18 +1843,6 @@ private void CaptureRegion(CaptureType captureType, TaskSettings taskSettings, b
rectangleRegion.AreaManager.IncludeControls = true;
surface = rectangleRegion;
break;
case CaptureType.RoundedRectangle:
surface = new RoundedRectangleRegion();
break;
case CaptureType.Ellipse:
surface = new EllipseRegion();
break;
case CaptureType.Triangle:
surface = new TriangleRegion();
break;
case CaptureType.Diamond:
surface = new DiamondRegion();
break;
case CaptureType.Polygon:
surface = new PolygonRegion();
break;