Added mouse events to DrawableObject, if object clicked then handle mouse input, crop confirm button works now

This commit is contained in:
Jaex 2017-12-12 19:12:25 +03:00
parent e1a86be0fa
commit 2c4943234f
3 changed files with 25 additions and 6 deletions

View file

@ -24,12 +24,17 @@
#endregion License Information (GPL v3)
using System.Drawing;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
internal abstract class DrawableObject
{
public event MouseEventHandler MousePressed;
public event MouseEventHandler MouseReleased;
public bool Visible { get; set; }
public bool HandleMouseInput { get; set; } = true;
public Rectangle Rectangle { get; set; }
public bool IsCursorHover { get; set; }
public bool IsDragging { get; protected set; }
@ -54,11 +59,21 @@ public virtual void OnDraw(Graphics g)
public virtual void OnMousePressed(Point position)
{
IsDragging = true;
if (MousePressed != null)
{
MousePressed(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
}
}
public virtual void OnMouseReleased(Point position)
{
IsDragging = false;
if (MouseReleased != null)
{
MouseReleased(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
}
}
}
}

View file

@ -208,7 +208,7 @@ public bool NodesVisible
}
}
public bool IsCursorOnNode => NodesVisible && ResizeNodes.Any(node => node.IsCursorHover);
public bool IsCursorOnObject => DrawableObjects.Any(x => x.HandleMouseInput && x.IsCursorHover);
public event Action<BaseShape> CurrentShapeChanged;
public event Action<ShapeType> CurrentShapeTypeChanged;
@ -696,7 +696,7 @@ public void Update()
private void StartRegionSelection()
{
if (IsCursorOnNode)
if (IsCursorOnObject)
{
return;
}
@ -1003,7 +1003,7 @@ private void UpdateCurrentHoverShape()
private BaseShape CheckHover()
{
if (!IsCursorOnNode && !IsCreating && !IsMoving && !IsResizing)
if (!IsCursorOnObject && !IsCreating && !IsMoving && !IsResizing)
{
BaseShape shape = GetIntersectShape();

View file

@ -24,6 +24,7 @@
#endregion License Information (GPL v3)
using System.Drawing;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
@ -41,7 +42,6 @@ public override void OnUpdate()
if (confirmButton != null)
{
confirmButton.Visible = true;
confirmButton.Rectangle = new Rectangle(Rectangle.Right - buttonSize.Width, Rectangle.Bottom + buttonOffset,
buttonSize.Width, buttonSize.Height);
}
@ -57,11 +57,15 @@ public override void OnDraw(Graphics g)
public override void OnCreated()
{
confirmButton = new ConfirmButton();
confirmButton = new ConfirmButton()
{
Visible = true
};
confirmButton.MousePressed += ConfirmButton_MousePressed;
Manager.DrawableObjects.Add(confirmButton);
}
private void ConfirmCrop()
private void ConfirmButton_MousePressed(object sender, MouseEventArgs e)
{
if (IsValidShape)
{