Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
823 chris 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Windows.Forms;
7
using System.Windows.Forms.VisualStyles;
8
using System.Drawing;
9
using System.ComponentModel;
10
using System.ComponentModel.Design;
11
 
12
using BauzoidNET.math;
13
 
14
namespace BauzoidNET.controls
15
{
16
    public class CheckToolButton : CheckBox
17
    {
18
        private int mOffset = 3;
19
 
20
        private bool mIsHovering = false;
21
 
22
        public CheckToolButton()
23
            : base()
24
        {
25
            this.Appearance = Appearance.Button;
26
            this.Font = new Font(Font.FontFamily, 6.5f, Font.Style);
27
            this.AutoSize = false;
28
        }
29
 
30
        protected override void OnPaint(PaintEventArgs e)
31
        {
32
            Rectangle clientRect = new Rectangle(0, 0, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
33
 
34
            Graphics g = e.Graphics;
35
 
36
            ButtonRenderer.DrawParentBackground(g, e.ClipRectangle, this);
37
 
38
            if (this.Appearance == System.Windows.Forms.Appearance.Button)
39
            {
40
                // Background
41
                if (this.Checked)
42
                {
43
                    byte red = (byte)MathUtil.clamp((SystemColors.Highlight.R + SystemColors.ButtonFace.R)/2, 0, 255);
44
                    byte green = (byte)MathUtil.clamp((SystemColors.Highlight.G + SystemColors.ButtonFace.G) / 2, 0, 255);
45
                    byte blue = (byte)MathUtil.clamp((SystemColors.Highlight.B + SystemColors.ButtonFace.B) / 2, 0, 255);
46
                    Color c = Color.FromArgb(red, green, blue);
47
                    g.FillRectangle(new SolidBrush(c), e.ClipRectangle);
48
                }
49
                else
50
                {
51
                    //g.FillRectangle(new SolidBrush(Color.Blue), e.ClipRectangle);
52
                }
53
 
54
                // Image
55
                if (this.Image != null)
56
                {
57
                    Rectangle r = new Rectangle((clientRect.Width - this.Image.Width - mOffset), (clientRect.Height - this.Image.Height - mOffset), this.Image.Width, this.Image.Height);
58
 
59
                    /*if (this.Checked)
60
                        r.Offset(1, 1);*/
61
 
62
                    g.DrawImage(this.Image, r);
63
                }
64
 
65
                if (this.Text != "")
66
                {
67
                    g.DrawString(this.Text, Font, SystemBrushes.ActiveCaptionText, mOffset, mOffset);
68
                }
69
 
70
                // Outline
71
                if (this.Checked || mIsHovering)
72
                {
73
                    g.DrawRectangle(new Pen(SystemColors.Highlight, 1), clientRect);
74
                }
75
                else
76
                {
77
                    g.DrawRectangle(new Pen(Color.Black, 1), clientRect);
78
                }
79
            }
80
            else
81
            {
82
                base.OnPaint(e);
83
            }
84
        }
85
 
86
        protected override void OnMouseEnter(EventArgs eventargs)
87
        {
88
            mIsHovering = true;
89
 
90
            base.OnMouseEnter(eventargs);
91
        }
92
 
93
        protected override void OnMouseLeave(EventArgs eventargs)
94
        {
95
            mIsHovering = false;
96
 
97
            base.OnMouseLeave(eventargs);
98
        }
99
 
100
        [Description("Offset of Text/Image into Button"), Category("Appearance")]
101
        public int Offset
102
        {
103
            get { return mOffset; }
104
            set
105
            {
106
                mOffset = value;
107
                Invalidate();
108
            }
109
        }
110
    }
111
}