mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Added MouseEnter, MouseLeave events to DrawableObject, show hand cursor for buttons
This commit is contained in:
parent
565da7acd3
commit
1b5f446a6d
5 changed files with 69 additions and 17 deletions
|
@ -89,7 +89,7 @@ private void InitializeComponent()
|
|||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "DownloaderForm";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.UpdaterForm_FormClosing);
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DownloaderForm_FormClosing);
|
||||
this.Shown += new System.EventHandler(this.DownloaderForm_Shown);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ private void fileDownloader_DownloadCompleted(object sender, EventArgs e)
|
|||
}
|
||||
}
|
||||
|
||||
private void UpdaterForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
private void DownloaderForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (Status == DownloaderFormStatus.DownloadStarted && fileDownloader != null)
|
||||
{
|
||||
|
|
|
@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
@ -30,13 +31,39 @@ namespace ShareX.ScreenCaptureLib
|
|||
{
|
||||
internal abstract class DrawableObject
|
||||
{
|
||||
public event MouseEventHandler MousePressed;
|
||||
public event MouseEventHandler MouseReleased;
|
||||
public event MouseEventHandler MouseDown, MouseUp;
|
||||
public event Action MouseEnter, MouseLeave;
|
||||
|
||||
public bool Visible { get; set; }
|
||||
public bool HandleMouseInput { get; set; } = true;
|
||||
public Rectangle Rectangle { get; set; }
|
||||
public bool IsCursorHover { get; set; }
|
||||
|
||||
private bool isCursorHover;
|
||||
|
||||
public bool IsCursorHover
|
||||
{
|
||||
get
|
||||
{
|
||||
return isCursorHover;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (isCursorHover != value)
|
||||
{
|
||||
isCursorHover = value;
|
||||
|
||||
if (isCursorHover)
|
||||
{
|
||||
OnMouseEnter();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnMouseLeave();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDragging { get; protected set; }
|
||||
public int Order { get; set; }
|
||||
|
||||
|
@ -56,23 +83,39 @@ public virtual void OnDraw(Graphics g)
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void OnMousePressed(Point position)
|
||||
public virtual void OnMouseEnter()
|
||||
{
|
||||
IsDragging = true;
|
||||
|
||||
if (MousePressed != null)
|
||||
if (MouseEnter != null)
|
||||
{
|
||||
MousePressed(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
|
||||
MouseEnter();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnMouseReleased(Point position)
|
||||
public virtual void OnMouseLeave()
|
||||
{
|
||||
if (MouseLeave != null)
|
||||
{
|
||||
MouseLeave();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnMouseDown(Point position)
|
||||
{
|
||||
IsDragging = true;
|
||||
|
||||
if (MouseDown != null)
|
||||
{
|
||||
MouseDown(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnMouseUp(Point position)
|
||||
{
|
||||
IsDragging = false;
|
||||
|
||||
if (MouseReleased != null)
|
||||
if (MouseUp != null)
|
||||
{
|
||||
MouseReleased(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
|
||||
MouseUp(this, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -814,7 +814,7 @@ internal void UpdateObjects()
|
|||
{
|
||||
if (InputManager.IsMousePressed(MouseButtons.Left))
|
||||
{
|
||||
obj.OnMousePressed(position);
|
||||
obj.OnMouseDown(position);
|
||||
}
|
||||
|
||||
for (int j = i + 1; j < objects.Length; j++)
|
||||
|
@ -835,7 +835,7 @@ internal void UpdateObjects()
|
|||
{
|
||||
if (obj.IsDragging)
|
||||
{
|
||||
obj.OnMouseReleased(position);
|
||||
obj.OnMouseUp(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,9 @@ public override void OnCreated()
|
|||
Rectangle = new Rectangle(new Point(), buttonSize),
|
||||
Visible = true
|
||||
};
|
||||
confirmButton.MousePressed += ConfirmButton_MousePressed;
|
||||
confirmButton.MouseDown += ConfirmButton_MousePressed;
|
||||
confirmButton.MouseEnter += () => Manager.Form.Cursor = Cursors.Hand;
|
||||
confirmButton.MouseLeave += () => Manager.Form.SetDefaultCursor();
|
||||
Manager.DrawableObjects.Add(confirmButton);
|
||||
|
||||
cancelButton = new ButtonObject()
|
||||
|
@ -82,7 +84,9 @@ public override void OnCreated()
|
|||
Rectangle = new Rectangle(new Point(), buttonSize),
|
||||
Visible = true
|
||||
};
|
||||
cancelButton.MousePressed += CancelButton_MousePressed;
|
||||
cancelButton.MouseDown += CancelButton_MousePressed;
|
||||
cancelButton.MouseEnter += () => Manager.Form.Cursor = Cursors.Hand;
|
||||
cancelButton.MouseLeave += () => Manager.Form.SetDefaultCursor();
|
||||
Manager.DrawableObjects.Add(cancelButton);
|
||||
}
|
||||
|
||||
|
@ -101,6 +105,11 @@ public override void Dispose()
|
|||
{
|
||||
base.Dispose();
|
||||
|
||||
if (confirmButton.IsCursorHover || cancelButton.IsCursorHover)
|
||||
{
|
||||
Manager.Form.SetDefaultCursor();
|
||||
}
|
||||
|
||||
if (confirmButton != null)
|
||||
{
|
||||
Manager.DrawableObjects.Remove(confirmButton);
|
||||
|
|
Loading…
Reference in a new issue