Make our custom buttons usable with Tab

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

@ -32,12 +32,11 @@ public class CustomButton : Drawable
get { return base.Enabled; } get { return base.Enabled; }
set set
{ {
if (base.Enabled != value) if (base.Enabled == value)
{ return;
base.Enabled = value; base.Enabled = value;
if (Loaded) if (Loaded)
Invalidate(); Invalidate();
}
} }
} }
@ -88,7 +87,11 @@ public class CustomButton : Drawable
} }
/// <summary>Default constructor. Sets <see cref="Enabled"/> to true.</summary> /// <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> /// <summary>Event raised when this control is resized.</summary>
/// <param name="e"></param> /// <param name="e"></param>
@ -106,11 +109,10 @@ public class CustomButton : Drawable
protected override void OnMouseDown(MouseEventArgs e) protected override void OnMouseDown(MouseEventArgs e)
{ {
base.OnMouseDown(e); base.OnMouseDown(e);
if (Enabled) if (!Enabled)
{ return;
mouseDown = true; mouseDown = true;
Invalidate(); Invalidate();
}
} }
/// <summary> /// <summary>
@ -137,6 +139,20 @@ public class CustomButton : Drawable
Invalidate(); 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> /// <summary>
/// Event raised when the mouse is released over this control's bounding box. /// Event raised when the mouse is released over this control's bounding box.
/// </summary> /// </summary>

@ -99,5 +99,8 @@ public class ImageButton : CustomButton
var xoffset = (this.Size.Width - size.Width) / 2; var xoffset = (this.Size.Width - size.Width) / 2;
var yoffset = (this.Size.Height - size.Height) / 2; var yoffset = (this.Size.Height - size.Height) / 2;
pe.Graphics.DrawImage(image, xoffset, yoffset, size.Width, size.Height); 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