Skip to content

Commit

Permalink
Add highlighting to button on mouseover
Browse files Browse the repository at this point in the history
  • Loading branch information
leezer3 committed Oct 8, 2023
1 parent 79d370d commit 1635057
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions source/LibRender2/Primitives/Button.cs
Expand Up @@ -8,6 +8,8 @@ public class Button : GLControl
{
/// <summary>The text displayed on the button</summary>
public string Text;
/// <summary>The highlight color of the button</summary>
public Color128 HighlightColor;
/// <summary>The color of the text on the button</summary>
public Color128 TextColor;
/// <summary>The font for the button</summary>
Expand All @@ -20,7 +22,19 @@ public Button(BaseRenderer renderer) : base(renderer)
public override void Draw()
{
Renderer.Rectangle.Draw(Texture, Location, Size, BackgroundColor);
if (CurrentlySelected)
{
Renderer.Rectangle.Draw(Texture, Location + 4, Size - 2, HighlightColor);
}
Renderer.OpenGlString.Draw(Font, Text, Location, TextAlignment.CenterLeft, TextColor);
}

public override void MouseMove(int x, int y)
{
if (x > Location.X && x < Location.X + Size.X && y > Location.Y && y < Location.Y + Size.Y)
{
CurrentlySelected = true;
}
}
}
}
2 changes: 2 additions & 0 deletions source/LibRender2/Primitives/GLControl.cs
Expand Up @@ -17,6 +17,8 @@ public abstract class GLControl
public Vector2 Location;
/// <summary>The stored size for the control</summary>
public Vector2 Size;
/// <summary>Whether the control is currently selected by the mouse</summary>
public bool CurrentlySelected;

protected GLControl(BaseRenderer renderer)
{
Expand Down
2 changes: 0 additions & 2 deletions source/LibRender2/Primitives/Textbox.cs
Expand Up @@ -33,8 +33,6 @@ public string Text
public readonly int Border;
/// <summary>The top line to be renderered</summary>
private int topLine;
/// <summary>Whether the textbox is currently selected by the mouse</summary>
public bool CurrentlySelected;
/// <summary>Whether the textbox can scroll</summary>
public bool CanScroll;
/// <summary>Used for internal size calculations</summary>
Expand Down

0 comments on commit 1635057

Please sign in to comment.