diff options
| author | FloppyDiskDrive <[email protected]> | 2017-09-11 20:37:33 -0500 |
|---|---|---|
| committer | FloppyDiskDrive <[email protected]> | 2017-09-11 20:37:33 -0500 |
| commit | cb10dfe5c2004580f480f3e84c445fe7877be79b (patch) | |
| tree | 748650f2069861bddb6972ecb39bbea336a816a5 /Histacom2.Engine/UI/ClassicButton.cs | |
| parent | 572117a8d2fe2e88ce72ecfbcf55598b02bddd62 (diff) | |
| parent | 584789ed8a37027db496d6c90873186fe461f021 (diff) | |
| download | histacom2-cb10dfe5c2004580f480f3e84c445fe7877be79b.tar.gz histacom2-cb10dfe5c2004580f480f3e84c445fe7877be79b.tar.bz2 histacom2-cb10dfe5c2004580f480f3e84c445fe7877be79b.zip | |
Merge remote-tracking branch 'refs/remotes/Histacom2-Devs/master'
Diffstat (limited to 'Histacom2.Engine/UI/ClassicButton.cs')
| -rw-r--r-- | Histacom2.Engine/UI/ClassicButton.cs | 86 |
1 files changed, 52 insertions, 34 deletions
diff --git a/Histacom2.Engine/UI/ClassicButton.cs b/Histacom2.Engine/UI/ClassicButton.cs index 26629a8..b761504 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,69 @@ using System.Windows.Forms; namespace Histacom2.Engine.UI { - public partial class ClassicButton : UserControl + public class ClassicButton : Control { - public ClassicButton() - { - InitializeComponent(); - } + private Color _lightBack; + private Color _darkBack; + private Font _font; - private void ClassicButton_SizeChanged(object sender, EventArgs e) + private bool _pressing = false; + + public ClassicButton() : base() { + if (SaveSystem.currentTheme != null) BackColor = SaveSystem.currentTheme.threeDObjectsColor; + else BackColor = Color.Silver; + _lightBack = ControlPaint.Light(BackColor, 50); + _darkBack = ControlPaint.Dark(BackColor, 50); - } + if (SaveSystem.currentTheme != null) ForeColor = SaveSystem.currentTheme.threeDObjectsTextColor; + else ForeColor = Color.Black; - private void ClassicButton_MouseDown(object sender, MouseEventArgs e) - { - this.BackColor = Color.White; - borderpart.BackColor = Color.Black; - lessgraystuff.Location = new Point(1, 1); - } + if (SaveSystem.currentTheme != null) _font = SaveSystem.currentTheme.buttonFont; + else _font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular); - private void ClassicButton_Paint(object sender, PaintEventArgs e) - { - e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; - base.OnPaint(e); + 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); - } - private void ClassicButton_MouseUp(object sender, MouseEventArgs e) - { - this.BackColor = Color.Black; - borderpart.BackColor = Color.White; - lessgraystuff.Location = new Point(0, 0); - } + if (SaveSystem.currentTheme != null) BackColor = SaveSystem.currentTheme.threeDObjectsColor; + else BackColor = Color.Silver; - private void ClassicButton_Resize(object sender, EventArgs e) - { - 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); + _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.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; + + if (_pressing) + { + 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), ((Width / 2) + 1) + Padding.Left, (Height / 2) - (g.MeasureString(Text, Font).Height / 2) + 2, 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)); + + g.DrawString(Text, _font, new SolidBrush(ForeColor), (Width / 2) + Padding.Left, (Height / 2) - (g.MeasureString(Text, Font).Height / 2) + 1, sf); + } } + } -}
\ No newline at end of file +} |
