diff options
Diffstat (limited to 'Histacom2.Engine/UI/ClassicButton.cs')
| -rw-r--r-- | Histacom2.Engine/UI/ClassicButton.cs | 102 |
1 files changed, 72 insertions, 30 deletions
diff --git a/Histacom2.Engine/UI/ClassicButton.cs b/Histacom2.Engine/UI/ClassicButton.cs index 26629a8..4ccdbe6 100644 --- a/Histacom2.Engine/UI/ClassicButton.cs +++ b/Histacom2.Engine/UI/ClassicButton.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Drawing; -using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,49 +8,93 @@ using System.Windows.Forms; namespace Histacom2.Engine.UI { - public partial class ClassicButton : UserControl + public class ClassicButton : Control, IButtonControl { - public ClassicButton() - { - InitializeComponent(); - } + private Color _lightBack; + private Color _darkBack; - private void ClassicButton_SizeChanged(object sender, EventArgs e) - { + private bool _pressing = false; - } + public DialogResult DialogResult { get; set; } - private void ClassicButton_MouseDown(object sender, MouseEventArgs e) - { - this.BackColor = Color.White; - borderpart.BackColor = Color.Black; - lessgraystuff.Location = new Point(1, 1); - } + public bool AdaptBackColorWithTheme { get; set; } + public bool AdaptForeColorWithTheme { get; set; } + public bool AdaptFontWithTheme { get; set; } - private void ClassicButton_Paint(object sender, PaintEventArgs e) + public ClassicButton() : base() { - e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; - base.OnPaint(e); + AdaptBackColorWithTheme = true; + AdaptForeColorWithTheme = true; + AdaptFontWithTheme = true; + if (SaveSystem.currentTheme != null) BackColor = SaveSystem.currentTheme.threeDObjectsColor; + else BackColor = Color.Silver; + _lightBack = ControlPaint.Light(BackColor, 50); + _darkBack = ControlPaint.Dark(BackColor, 50); + + MouseDown += (s, e) => { _pressing = true; Invalidate(); }; + MouseUp += (s, e) => { _pressing = false; Invalidate(); }; + Invalidate(); } - private void lessgraystuff_Paint(object sender, PaintEventArgs e) + protected override void OnPaint(PaintEventArgs e) { - e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; base.OnPaint(e); + + if (SaveSystem.currentTheme != null && AdaptBackColorWithTheme) BackColor = SaveSystem.currentTheme.threeDObjectsColor; + + if (AdaptForeColorWithTheme) + { + if (SaveSystem.currentTheme != null) ForeColor = SaveSystem.currentTheme.threeDObjectsTextColor; + else ForeColor = Color.Black; + } + + if (AdaptFontWithTheme) + { + if (SaveSystem.currentTheme != null) Font = SaveSystem.currentTheme.buttonFont; + else Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular); + } + + _lightBack = Paintbrush.GetLightFromColor(BackColor); + _darkBack = Paintbrush.GetDarkFromColor(BackColor); + + var g = e.Graphics; + g.Clear(BackColor); + + g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; + StringFormat sf = new StringFormat(); + sf.Alignment = StringAlignment.Center; + sf.LineAlignment = StringAlignment.Center; + sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; + + if (_pressing && Enabled) + { + g.FillRectangle(new SolidBrush(_lightBack), new Rectangle(0, 0, Width, Height)); + g.FillRectangle(Brushes.Black, new Rectangle(0, 0, Width - 1, Height - 1)); + g.FillRectangle(new SolidBrush(_darkBack), new Rectangle(1, 1, Width - 2, Height - 2)); + g.FillRectangle(new SolidBrush(BackColor), new Rectangle(2, 2, Width - 3, Height - 3)); + + g.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(2, 2, Width - 3, Height - 3), sf); + } + else + { + g.FillRectangle(Brushes.Black, new Rectangle(0, 0, Width, Height)); + g.FillRectangle(new SolidBrush(_lightBack), new Rectangle(0, 0, Width - 1, Height - 1)); + g.FillRectangle(new SolidBrush(_darkBack), new Rectangle(1, 1, Width - 2, Height - 2)); + g.FillRectangle(new SolidBrush(BackColor), new Rectangle(1, 1, Width - 3, Height - 3)); + + if (Enabled) g.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(1, 1, Width - 3, Height - 3), sf); + else g.DrawString(Text, Font, new SolidBrush(_darkBack), new Rectangle(1, 1, Width - 3, Height - 3), sf); + } } - private void ClassicButton_MouseUp(object sender, MouseEventArgs e) + public void NotifyDefault(bool value) { - this.BackColor = Color.Black; - borderpart.BackColor = Color.White; - lessgraystuff.Location = new Point(0, 0); + } - private void ClassicButton_Resize(object sender, EventArgs e) + public void PerformClick() { - borderpart.Size = new Size(this.Width - 1, this.Height - 1); - graystuff.Size = new Size(this.Width - 2, this.Height - 2); - lessgraystuff.Size = new Size(this.Width - 3, this.Height - 3); + this.OnClick(new EventArgs()); } } -}
\ No newline at end of file +} |
