2017-07-03 01:48:10 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ShiftOS.Engine;
|
2017-07-04 21:57:29 +00:00
|
|
|
|
using ShiftOS.Frontend.GraphicsSubsystem;
|
2017-07-03 01:48:10 +00:00
|
|
|
|
|
|
|
|
|
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 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 21:57:29 +00:00
|
|
|
|
protected override void OnPaint(GraphicsContext gfx)
|
2017-07-03 01:48:10 +00:00
|
|
|
|
{
|
2017-07-04 21:57:29 +00:00
|
|
|
|
var bgCol = SkinEngine.LoadedSkin.ButtonBackgroundColor.ToMonoColor();
|
|
|
|
|
var fgCol = SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor();
|
2017-07-03 01:48:10 +00:00
|
|
|
|
if (ContainsMouse)
|
2017-07-04 21:57:29 +00:00
|
|
|
|
bgCol = SkinEngine.LoadedSkin.ButtonHoverColor.ToMonoColor();
|
2017-07-03 01:48:10 +00:00
|
|
|
|
if (MouseLeftDown)
|
2017-07-04 21:57:29 +00:00
|
|
|
|
bgCol = SkinEngine.LoadedSkin.ButtonPressedColor.ToMonoColor();
|
2017-07-03 01:48:10 +00:00
|
|
|
|
|
2017-07-03 12:55:21 +00:00
|
|
|
|
base.OnPaint(gfx);
|
2017-07-04 21:57:29 +00:00
|
|
|
|
base.OnPaint(gfx);
|
2017-07-03 01:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|