forked from daPhie79/ProgressODoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlainBorderPainter.cs
158 lines (143 loc) · 5.43 KB
/
PlainBorderPainter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
namespace ProgressODoom {
/// <summary></summary>
[ToolboxBitmapAttribute(typeof(ProgressODoom.PlainBorderPainter), "Icons.PlainBorderPainter.ico")]
public class PlainBorderPainter : Component, IProgressBorderPainter, IDisposable {
private Color color;
private Pen pent;
private Pen penb;
private Pen cleart;
private Pen clearb;
private bool rounded = false;
private PlainBorderStyle style = PlainBorderStyle.Flat;
private EventHandler onPropertiesChanged;
/// <summary></summary>
public event EventHandler PropertiesChanged {
add {
if (onPropertiesChanged != null) {
foreach (Delegate d in onPropertiesChanged.GetInvocationList()) {
if (object.ReferenceEquals(d, value)) { return; }
}
}
onPropertiesChanged = (EventHandler)Delegate.Combine(onPropertiesChanged, value);
}
remove { onPropertiesChanged = (EventHandler)Delegate.Remove(onPropertiesChanged, value); }
}
private void FireChange() {
if (onPropertiesChanged != null) { onPropertiesChanged(this, EventArgs.Empty); }
}
/// <summary></summary>
public PlainBorderPainter() {
this.Color = Color.Black;
//this.clear = new Pen(new SolidBrush(SystemColors.Control));
}
/// <summary></summary>
/// <param name="color"></param>
public PlainBorderPainter(Color color) {
this.Color = color;
//this.clear = new Pen(new SolidBrush(SystemColors.Control));
}
/// <summary></summary>
[Category("Appearance"), Description("Gets or sets the border color"), Browsable(true)]
public Color Color {
get { return color; }
set {
color = value;
if (style == PlainBorderStyle.Flat) {
pent = new Pen(new SolidBrush(color), 1f);
penb = pent;
this.cleart = new Pen(new SolidBrush(Color.FromArgb(64, color.R, color.G, color.B)));
this.clearb = cleart;
FireChange();
}
}
}
/// <summary></summary>
[Category("Appearance"), Description("Determines wether or not to make the border a flat sqaure"), Browsable(true)]
public bool RoundedCorners {
get { return rounded; }
set { rounded = value; FireChange(); }
}
[Category("Appearance"), Description("Gets or sets the border style"), Browsable(true)]
public PlainBorderStyle Style {
get { return style; }
set {
style = value;
switch (style) {
case PlainBorderStyle.Flat:
pent = new Pen(new SolidBrush(color), 1f);
penb = pent;
this.cleart = new Pen(new SolidBrush(Color.FromArgb(64, color.R, color.G, color.B)));
this.clearb = cleart;
break;
case PlainBorderStyle.Raised:
pent = new Pen(new SolidBrush(SystemColors.ControlLightLight), 1f);
penb = new Pen(new SolidBrush(SystemColors.ControlDark), 1f);
this.cleart = new Pen(new SolidBrush(Color.FromArgb(64, SystemColors.ControlLightLight.R, SystemColors.ControlLightLight.G, SystemColors.ControlLightLight.B)));
this.clearb = new Pen(new SolidBrush(Color.FromArgb(64, SystemColors.ControlDark.R, SystemColors.ControlDark.G, SystemColors.ControlDark.B)));
break;
case PlainBorderStyle.Sunken:
pent = new Pen(new SolidBrush(SystemColors.ControlDark), 1f);
penb = new Pen(new SolidBrush(SystemColors.ControlLightLight), 1f);
this.cleart = new Pen(new SolidBrush(Color.FromArgb(64, SystemColors.ControlDark.R, SystemColors.ControlDark.G, SystemColors.ControlDark.B)));
this.clearb = new Pen(new SolidBrush(Color.FromArgb(64, SystemColors.ControlLightLight.R, SystemColors.ControlLightLight.G, SystemColors.ControlLightLight.B)));
break;
}
FireChange();
}
}
/// <summary></summary>
[Browsable(false)]
public int BorderWidth {
get { return 1; }
}
/// <summary></summary>
/// <param name="box"></param>
/// <param name="g"></param>
public void PaintBorder(Rectangle box, Graphics g) {
//try {
// box.Width -= 1;
// box.Height -= 1;
//} catch {}
if (rounded) {
//// draws the left and right side (because they're shorter) to cover the corner pixels.
//g.DrawLine(clear, box.X, 0, box.X, box.Height);
//g.DrawLine(clear, box.Width, 0, box.Width, box.Height);
g.DrawLine(cleart, box.X, box.Y, box.Right - 1, box.Y); // top
g.DrawLine(cleart, box.X, box.Y, box.X, box.Bottom - 1); // left
g.DrawLine(clearb, box.X, box.Bottom, box.Right, box.Bottom); // bottom
g.DrawLine(clearb, box.Right, box.Y, box.Right, box.Bottom); // right
//g.DrawRectangle(clear, box);
g.DrawLine(pent, box.X + 1, box.Y, box.Right - 1, box.Y); // top
g.DrawLine(penb, box.X + 1, box.Bottom, box.Right - 1, box.Bottom); // bottom
g.DrawLine(pent, box.X, box.Y + 1, box.X, box.Bottom - 1); // left
g.DrawLine(penb, box.Right, box.Y + 1, box.Right, box.Bottom - 1); // right
} else {
//g.DrawRectangle(pen, box);
g.DrawLine(pent, box.X, box.Y, box.Right, box.Y); // top
g.DrawLine(pent, box.X, box.Y, box.X, box.Bottom); // left
g.DrawLine(penb, box.X, box.Bottom, box.Right, box.Bottom); // bottom
g.DrawLine(penb, box.Right, box.Y, box.Right, box.Bottom); // right
}
}
/// <summary></summary>
public void Resize(Rectangle box) {
}
/// <summary></summary>
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
pent.Dispose();
penb.Dispose();
cleart.Dispose();
clearb.Dispose();
}
/// <summary></summary>
public enum PlainBorderStyle {
Flat, Sunken, Raised
}
}
}