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