mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-04 04:06:05 +13:00
Added mouse events to DrawableObject, if object clicked then handle mouse input, crop confirm button works now
This commit is contained in:
parent
e1a86be0fa
commit
2c4943234f
3 changed files with 25 additions and 6 deletions
|
@ -24,12 +24,17 @@ You should have received a copy of the GNU General Public License
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.ScreenCaptureLib
|
namespace ShareX.ScreenCaptureLib
|
||||||
{
|
{
|
||||||
internal abstract class DrawableObject
|
internal abstract class DrawableObject
|
||||||
{
|
{
|
||||||
|
public event MouseEventHandler MousePressed;
|
||||||
|
public event MouseEventHandler MouseReleased;
|
||||||
|
|
||||||
public bool Visible { get; set; }
|
public bool Visible { get; set; }
|
||||||
|
public bool HandleMouseInput { get; set; } = true;
|
||||||
public Rectangle Rectangle { get; set; }
|
public Rectangle Rectangle { get; set; }
|
||||||
public bool IsCursorHover { get; set; }
|
public bool IsCursorHover { get; set; }
|
||||||
public bool IsDragging { get; protected set; }
|
public bool IsDragging { get; protected set; }
|
||||||
|
@ -54,11 +59,21 @@ public virtual void OnDraw(Graphics g)
|
||||||
public virtual void OnMousePressed(Point position)
|
public virtual void OnMousePressed(Point position)
|
||||||
{
|
{
|
||||||
IsDragging = true;
|
IsDragging = true;
|
||||||
|
|
||||||
|
if (MousePressed != null)
|
||||||
|
{
|
||||||
|
MousePressed(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnMouseReleased(Point position)
|
public virtual void OnMouseReleased(Point position)
|
||||||
{
|
{
|
||||||
IsDragging = false;
|
IsDragging = false;
|
||||||
|
|
||||||
|
if (MouseReleased != null)
|
||||||
|
{
|
||||||
|
MouseReleased(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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<BaseShape> CurrentShapeChanged;
|
||||||
public event Action<ShapeType> CurrentShapeTypeChanged;
|
public event Action<ShapeType> CurrentShapeTypeChanged;
|
||||||
|
@ -696,7 +696,7 @@ public void Update()
|
||||||
|
|
||||||
private void StartRegionSelection()
|
private void StartRegionSelection()
|
||||||
{
|
{
|
||||||
if (IsCursorOnNode)
|
if (IsCursorOnObject)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1003,7 +1003,7 @@ private void UpdateCurrentHoverShape()
|
||||||
|
|
||||||
private BaseShape CheckHover()
|
private BaseShape CheckHover()
|
||||||
{
|
{
|
||||||
if (!IsCursorOnNode && !IsCreating && !IsMoving && !IsResizing)
|
if (!IsCursorOnObject && !IsCreating && !IsMoving && !IsResizing)
|
||||||
{
|
{
|
||||||
BaseShape shape = GetIntersectShape();
|
BaseShape shape = GetIntersectShape();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.ScreenCaptureLib
|
namespace ShareX.ScreenCaptureLib
|
||||||
{
|
{
|
||||||
|
@ -41,7 +42,6 @@ public override void OnUpdate()
|
||||||
|
|
||||||
if (confirmButton != null)
|
if (confirmButton != null)
|
||||||
{
|
{
|
||||||
confirmButton.Visible = true;
|
|
||||||
confirmButton.Rectangle = new Rectangle(Rectangle.Right - buttonSize.Width, Rectangle.Bottom + buttonOffset,
|
confirmButton.Rectangle = new Rectangle(Rectangle.Right - buttonSize.Width, Rectangle.Bottom + buttonOffset,
|
||||||
buttonSize.Width, buttonSize.Height);
|
buttonSize.Width, buttonSize.Height);
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,15 @@ public override void OnDraw(Graphics g)
|
||||||
|
|
||||||
public override void OnCreated()
|
public override void OnCreated()
|
||||||
{
|
{
|
||||||
confirmButton = new ConfirmButton();
|
confirmButton = new ConfirmButton()
|
||||||
|
{
|
||||||
|
Visible = true
|
||||||
|
};
|
||||||
|
confirmButton.MousePressed += ConfirmButton_MousePressed;
|
||||||
Manager.DrawableObjects.Add(confirmButton);
|
Manager.DrawableObjects.Add(confirmButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConfirmCrop()
|
private void ConfirmButton_MousePressed(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (IsValidShape)
|
if (IsValidShape)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue