From add923d9149042b8ed8b248f1fe0f411f8968040 Mon Sep 17 00:00:00 2001 From: Jaex Date: Tue, 24 May 2016 20:31:40 +0300 Subject: [PATCH] Use int instead of float for nodes --- .../Forms/BaseRegionForm.cs | 6 ++-- .../Forms/PolygonRegionForm.cs | 4 +-- .../RegionHelpers/DrawObject.cs | 16 ++-------- .../RegionHelpers/NodeObject.cs | 15 +++++----- .../Shapes/AnnotationOptions.cs | 2 +- .../Shapes/ResizeManager.cs | 30 +++++++++---------- 6 files changed, 32 insertions(+), 41 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Forms/BaseRegionForm.cs b/ShareX.ScreenCaptureLib/Forms/BaseRegionForm.cs index e0c9a42a0..170d3507a 100644 --- a/ShareX.ScreenCaptureLib/Forms/BaseRegionForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/BaseRegionForm.cs @@ -309,9 +309,9 @@ public void Close(RegionResult result) if (obj.Visible) { - obj.IsMouseHover = obj.Rectangle.Contains(InputManager.MousePosition0Based); + obj.IsCursorHover = obj.Rectangle.Contains(InputManager.MousePosition0Based); - if (obj.IsMouseHover) + if (obj.IsCursorHover) { if (InputManager.IsMousePressed(MouseButtons.Left)) { @@ -320,7 +320,7 @@ public void Close(RegionResult result) for (int y = i + 1; y < objects.Count(); y++) { - objects[y].IsMouseHover = false; + objects[y].IsCursorHover = false; } break; diff --git a/ShareX.ScreenCaptureLib/Forms/PolygonRegionForm.cs b/ShareX.ScreenCaptureLib/Forms/PolygonRegionForm.cs index 5bbbcb770..ae2a9bd70 100644 --- a/ShareX.ScreenCaptureLib/Forms/PolygonRegionForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/PolygonRegionForm.cs @@ -50,7 +50,7 @@ private void PolygonRegionForm_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { - if (drawableObjects.Cast().Any(node => node.IsMouseHover || node.IsDragging)) + if (drawableObjects.Cast().Any(node => node.IsCursorHover || node.IsDragging)) { return; } @@ -70,7 +70,7 @@ private void PolygonRegionForm_MouseDown(object sender, MouseEventArgs e) { foreach (NodeObject node in nodes) { - if (node.IsMouseHover) + if (node.IsCursorHover) { nodes.Remove(node); drawableObjects.Remove(node); diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/DrawObject.cs b/ShareX.ScreenCaptureLib/RegionHelpers/DrawObject.cs index 062e657ad..a606a8ece 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/DrawObject.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/DrawObject.cs @@ -30,24 +30,14 @@ namespace ShareX.ScreenCaptureLib public class DrawableObject { public bool Visible { get; set; } - public RectangleF Rectangle { get; set; } - public bool IsMouseHover { get; set; } + public Rectangle Rectangle { get; set; } + public bool IsCursorHover { get; set; } public bool IsDragging { get; set; } public int Order { get; set; } - public void Show() - { - Visible = true; - } - - public void Hide() - { - Visible = false; - } - public virtual void Draw(Graphics g) { - if (IsMouseHover) + if (IsCursorHover) { g.FillRectangle(Brushes.Green, Rectangle); } diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/NodeObject.cs b/ShareX.ScreenCaptureLib/RegionHelpers/NodeObject.cs index 7d8e1f068..714892f76 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/NodeObject.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/NodeObject.cs @@ -30,9 +30,9 @@ namespace ShareX.ScreenCaptureLib { internal class NodeObject : DrawableObject { - private PointF position; + private Point position; - public PointF Position + public Point Position { get { @@ -41,24 +41,25 @@ public PointF Position set { position = value; - Rectangle = new RectangleF(position.X - (NodeSize - 1) / 2, position.Y - (NodeSize - 1) / 2, NodeSize, NodeSize); + + Rectangle = new Rectangle(position.X - (NodeSize - 1) / 2, position.Y - (NodeSize - 1) / 2, NodeSize, NodeSize); } } - public float NodeSize { get; set; } + public int NodeSize { get; set; } public NodeShape Shape { get; set; } - public NodeObject(float x = 0, float y = 0) + public NodeObject(int x = 0, int y = 0) { NodeSize = 13; Shape = NodeShape.Square; - Position = new PointF(x, y); + Position = new Point(x, y); } public override void Draw(Graphics g) { - Rectangle rect = new Rectangle((int)Rectangle.X, (int)Rectangle.Y, (int)Rectangle.Width - 1, (int)Rectangle.Height - 1); + Rectangle rect = new Rectangle(Rectangle.X, Rectangle.Y, Rectangle.Width - 1, Rectangle.Height - 1); switch (Shape) { diff --git a/ShareX.ScreenCaptureLib/Shapes/AnnotationOptions.cs b/ShareX.ScreenCaptureLib/Shapes/AnnotationOptions.cs index cdf13d246..440a582a6 100644 --- a/ShareX.ScreenCaptureLib/Shapes/AnnotationOptions.cs +++ b/ShareX.ScreenCaptureLib/Shapes/AnnotationOptions.cs @@ -49,7 +49,7 @@ public class AnnotationOptions // Step drawing public Color StepBorderColor { get; set; } = Color.White; - public int StepBorderSize { get; set; } = 2; + public int StepBorderSize { get; set; } = 0; public Color StepFillColor { get; set; } = Color.Red; // Blur effect diff --git a/ShareX.ScreenCaptureLib/Shapes/ResizeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ResizeManager.cs index 326c4710b..17dd73ea0 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ResizeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ResizeManager.cs @@ -262,7 +262,7 @@ private void form_KeyUp(object sender, KeyEventArgs e) public bool IsCursorOnNode() { - return Visible && nodes.Any(node => node.IsMouseHover); + return Visible && nodes.Any(node => node.IsCursorHover); } public void Show() @@ -287,22 +287,22 @@ private void UpdateNodePositions() { Rectangle rect = shape.Rectangle; - float xStart = rect.X; - float xMid = rect.X + rect.Width / 2; - float xEnd = rect.X + rect.Width - 1; + int xStart = rect.X; + int xMid = rect.X + rect.Width / 2; + int xEnd = rect.X + rect.Width - 1; - float yStart = rect.Y; - float yMid = rect.Y + rect.Height / 2; - float yEnd = rect.Y + rect.Height - 1; + int yStart = rect.Y; + int yMid = rect.Y + rect.Height / 2; + int yEnd = rect.Y + rect.Height - 1; - nodes[(int)NodePosition.TopLeft].Position = new PointF(xStart, yStart); - nodes[(int)NodePosition.Top].Position = new PointF(xMid, yStart); - nodes[(int)NodePosition.TopRight].Position = new PointF(xEnd, yStart); - nodes[(int)NodePosition.Right].Position = new PointF(xEnd, yMid); - nodes[(int)NodePosition.BottomRight].Position = new PointF(xEnd, yEnd); - nodes[(int)NodePosition.Bottom].Position = new PointF(xMid, yEnd); - nodes[(int)NodePosition.BottomLeft].Position = new PointF(xStart, yEnd); - nodes[(int)NodePosition.Left].Position = new PointF(xStart, yMid); + nodes[(int)NodePosition.TopLeft].Position = new Point(xStart, yStart); + nodes[(int)NodePosition.Top].Position = new Point(xMid, yStart); + nodes[(int)NodePosition.TopRight].Position = new Point(xEnd, yStart); + nodes[(int)NodePosition.Right].Position = new Point(xEnd, yMid); + nodes[(int)NodePosition.BottomRight].Position = new Point(xEnd, yEnd); + nodes[(int)NodePosition.Bottom].Position = new Point(xMid, yEnd); + nodes[(int)NodePosition.BottomLeft].Position = new Point(xStart, yEnd); + nodes[(int)NodePosition.Left].Position = new Point(xStart, yMid); } else if (shape.NodeType == NodeType.Line) {