Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
Updated Button
Browse files Browse the repository at this point in the history
  • Loading branch information
craftersmine committed Apr 19, 2019
1 parent 1d35bb7 commit ce36910
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions craftersmine.EtherEngine.Core/Objects/UIWidgets/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Button : UIWidget
private Size _measuredTextSize;
private Rectangle _textRenderBounds;
private bool _isClicked;
private int _frameCounter;
private int _currentAnimationFrame;

public Font Font { get; set; }
public string Text { get { return _text; } set { _text = value; _measuredTextSize = TextRenderer.MeasureText(_text, Font); _textRenderBounds = new Rectangle((int)X, (int)Y, _measuredTextSize.Width, _measuredTextSize.Height); } }
Expand All @@ -40,8 +42,39 @@ public Button(int width, int height, string text, Font font)

public override void OnRender(GLGDI renderer)
{
base.OnRender(renderer);
renderer.DrawString(_text, Font, TextColor, (Transform.Width / 2) - (_measuredTextSize.Width / 2), (Transform.Height / 2) - (_measuredTextSize.Width / 2), TextQuality.High);
byte objTransparencyCalculated = (byte)(255 * ObjectTransparency);

if (IsAnimated)
{
if (Animation != null)
{
if (_frameCounter == Animation.TicksPerFrame)
{
_frameCounter = 0;
_currentAnimationFrame++;
if (_currentAnimationFrame == Animation.FramesCount)
ResetAnimation();
}
renderer.DrawImage(Animation.AnimationFrames[_currentAnimationFrame].RenderableImage,
(int)Transform.X,
(int)Transform.Y,
Width,
Height,
new GLGDIPlus.BlendingValues(BlendingColor.R, BlendingColor.G, BlendingColor.B, objTransparencyCalculated));
_frameCounter++;
}
else IsAnimated = false;
}
else
{
renderer.DrawImage(Texture.RenderableImage,
(int)Transform.RendererX,
(int)Transform.RendererY,
Width,
Height,
new GLGDIPlus.BlendingValues(BlendingColor.R, BlendingColor.G, BlendingColor.B, objTransparencyCalculated));
}
renderer.DrawString(_text, Font, TextColor, (Transform.Width / 2) - (_measuredTextSize.Width / 2), (Transform.Height / 2) - (_measuredTextSize.Height / 2), TextQuality.High);
}

public override void OnMouseDown(int mouseX, int mouseY, bool mouseLeftButton, bool mouseMiddleButton, bool mouseRightButton)
Expand Down

0 comments on commit ce36910

Please sign in to comment.