ShiftOS_TheReturn/ShiftOS.Frontend/GUI/Button.cs

50 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftOS.Engine;
namespace ShiftOS.Frontend.GUI
{
public class Button : TextControl
{
public Button()
{
TextAlign = TextAlign.MiddleCenter;
Text = "Click me!";
}
protected override void OnLayout()
{
if(AutoSize == true)
{
int borderwidth = SkinEngine.LoadedSkin.ButtonBorderWidth * 2;
using (var gfx = Graphics.FromImage(new Bitmap(1, 1)))
{
var measure = gfx.MeasureString(this.Text, this.Font);
2017-07-03 12:55:21 +00:00
Width = borderwidth + (int)measure.Width + 16;
Height = borderwidth + (int)measure.Height + 12;
}
}
}
2017-07-03 12:55:21 +00:00
protected override void OnPaint(Graphics gfx)
{
Color bgCol = SkinEngine.LoadedSkin.ButtonBackgroundColor;
Color fgCol = SkinEngine.LoadedSkin.ControlTextColor;
if (ContainsMouse)
bgCol = SkinEngine.LoadedSkin.ButtonHoverColor;
if (MouseLeftDown)
bgCol = SkinEngine.LoadedSkin.ButtonPressedColor;
gfx.Clear(bgCol);
gfx.DrawRectangle(new Pen(new SolidBrush(fgCol), SkinEngine.LoadedSkin.ButtonBorderWidth), new Rectangle(0, 0, Width, Height));
2017-07-03 12:55:21 +00:00
base.OnPaint(gfx);
}
}
}