From 5b9cf79f4892fabd624e18a8f03d246ea344ae28 Mon Sep 17 00:00:00 2001 From: Jaex Date: Thu, 16 Jul 2015 22:07:06 +0300 Subject: [PATCH] Each region have its own angle and radius info and changeable in selected region --- .../Forms/DiamondRegion.cs | 39 ------ .../Forms/EllipseRegion.cs | 38 ------ .../Forms/RectangleRegion.cs | 81 ++---------- .../Forms/RoundedRectangleRegion.cs | 71 ----------- .../Forms/TriangleRegion.cs | 82 ------------ .../RegionHelpers/AreaManager.cs | 119 ++++++++++++++++-- .../RegionHelpers/RegionInfo.cs | 3 + .../ShareX.ScreenCaptureLib.csproj | 12 -- ShareX/Enums.cs | 4 - ShareX/Forms/MainForm.cs | 19 +-- 10 files changed, 126 insertions(+), 342 deletions(-) delete mode 100644 ShareX.ScreenCaptureLib/Forms/DiamondRegion.cs delete mode 100644 ShareX.ScreenCaptureLib/Forms/EllipseRegion.cs delete mode 100644 ShareX.ScreenCaptureLib/Forms/RoundedRectangleRegion.cs delete mode 100644 ShareX.ScreenCaptureLib/Forms/TriangleRegion.cs diff --git a/ShareX.ScreenCaptureLib/Forms/DiamondRegion.cs b/ShareX.ScreenCaptureLib/Forms/DiamondRegion.cs deleted file mode 100644 index 9b1cc1ebf..000000000 --- a/ShareX.ScreenCaptureLib/Forms/DiamondRegion.cs +++ /dev/null @@ -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 . -*/ - -#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); - } - } -} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/EllipseRegion.cs b/ShareX.ScreenCaptureLib/Forms/EllipseRegion.cs deleted file mode 100644 index d42dfdf90..000000000 --- a/ShareX.ScreenCaptureLib/Forms/EllipseRegion.cs +++ /dev/null @@ -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 . -*/ - -#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); - } - } -} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs b/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs index e3d8e33cc..658b1f1cc 100644 --- a/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs +++ b/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs @@ -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; } } diff --git a/ShareX.ScreenCaptureLib/Forms/RoundedRectangleRegion.cs b/ShareX.ScreenCaptureLib/Forms/RoundedRectangleRegion.cs deleted file mode 100644 index 835662ab1..000000000 --- a/ShareX.ScreenCaptureLib/Forms/RoundedRectangleRegion.cs +++ /dev/null @@ -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 . -*/ - -#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"); - } - } -} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/TriangleRegion.cs b/ShareX.ScreenCaptureLib/Forms/TriangleRegion.cs deleted file mode 100644 index b48cda3ca..000000000 --- a/ShareX.ScreenCaptureLib/Forms/TriangleRegion.cs +++ /dev/null @@ -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 . -*/ - -#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"); - } - } -} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs index f7c90832d..3ed63216d 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs @@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License #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 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(); 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) diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/RegionInfo.cs b/ShareX.ScreenCaptureLib/RegionHelpers/RegionInfo.cs index 50815c412..ca22ff4ea 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/RegionInfo.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/RegionInfo.cs @@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License #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) { diff --git a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj index 31c52555d..eaf2829e0 100644 --- a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj +++ b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj @@ -83,12 +83,6 @@ - - Form - - - Form - Form @@ -98,12 +92,6 @@ Form - - Form - - - Form - diff --git a/ShareX/Enums.cs b/ShareX/Enums.cs index 59ca36979..bed59b74f 100644 --- a/ShareX/Enums.cs +++ b/ShareX/Enums.cs @@ -120,10 +120,6 @@ public enum CaptureType ActiveWindow, RectangleWindow, Rectangle, - RoundedRectangle, - Ellipse, - Triangle, - Diamond, Polygon, Freehand, CustomRegion, diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 1fba0fb02..09a7e992a 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -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;