Make our custom buttons usable with Tab

pull/35/head
Miepee 4 years ago
parent 1703954c41
commit 672a2acba6

@ -32,14 +32,13 @@ public class CustomButton : Drawable
get { return base.Enabled; }
set
{
if (base.Enabled != value)
{
if (base.Enabled == value)
return;
base.Enabled = value;
if (Loaded)
Invalidate();
}
}
}
/// <summary>Gets or sets <see cref="pressed"/>.</summary>
public bool Pressed
@ -88,7 +87,11 @@ public class CustomButton : Drawable
}
/// <summary>Default constructor. Sets <see cref="Enabled"/> to true.</summary>
public CustomButton() { Enabled = true; }
public CustomButton()
{
Enabled = true;
CanFocus = true;
}
/// <summary>Event raised when this control is resized.</summary>
/// <param name="e"></param>
@ -106,12 +109,11 @@ public class CustomButton : Drawable
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (Enabled)
{
if (!Enabled)
return;
mouseDown = true;
Invalidate();
}
}
/// <summary>
/// Event raised when the mouse enters this control's bounding box.
@ -137,6 +139,20 @@ public class CustomButton : Drawable
Invalidate();
}
protected override void OnGotFocus(EventArgs e)
{
hover = true;
base.OnGotFocus(e);
Invalidate();
}
protected override void OnLostFocus(EventArgs e)
{
hover = false;
base.OnLostFocus(e);
Invalidate();
}
/// <summary>
/// Event raised when the mouse is released over this control's bounding box.
/// </summary>

@ -99,5 +99,8 @@ public class ImageButton : CustomButton
var xoffset = (this.Size.Width - size.Width) / 2;
var yoffset = (this.Size.Height - size.Height) / 2;
pe.Graphics.DrawImage(image, xoffset, yoffset, size.Width, size.Height);
if (Hover)
// This can probably be done prettier, but can't be bothered to much with it to be honest.
pe.Graphics.DrawRectangle(SystemColors.Highlight, xoffset, yoffset, size.Width, size.Height);
}
}
Loading…
Cancel
Save