forked from daPhie79/ProgressODoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RoundGlossPainter.cs
172 lines (154 loc) · 5.47 KB
/
RoundGlossPainter.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Collections.Generic;
namespace ProgressODoom {
/// <summary></summary>
public enum GlossStyle {
Top, Bottom, Both
}
/// <summary></summary>
[ToolboxBitmapAttribute(typeof(ProgressODoom.RoundGlossPainter), "Icons.RoundGlossPainter.ico")]
public class RoundGlossPainter : ChainedGlossPainter {
private GlossStyle style = GlossStyle.Both;
private int highAlpha = 240;
private int lowAlpha = 0;
private int fadewidth = 4;
private Brush highBrush;
private Brush lowBrush;
private Rectangle box;
private Color color = Color.White;
private Color topColor;
private Color botColor;
/// <summary></summary>
[Category("Appearance"), Description("Gets or sets the style for this progress gloss"), Browsable(true)]
public GlossStyle Style {
get { return this.style; }
set {
this.style = value;
FireChange();
}
}
/// <summary></summary>
[Category("Blending"), Description("Gets or sets the high alpha value"), Browsable(true)]
public int AlphaHigh {
get { return this.highAlpha; }
set {
if (value < 0 || value > 255) {
throw new ArgumentException("Alpha values must be between 0 and 255.");
}
this.highAlpha = value;
FireChange();
}
}
/// <summary></summary>
[Category("Blending"), Description("Gets or sets the low alpha value"), Browsable(true)]
public int AlphaLow {
get { return this.lowAlpha; }
set {
if (value < 0 || value > 255) {
throw new ArgumentException("Alpha values must be between 0 and 255.");
}
this.lowAlpha = value;
FireChange();
}
}
/// <summary></summary>
[Category("Blending"), Description("Gets or sets the number of pixels to blend over"), Browsable(true)]
public int TaperHeight {
get { return this.fadewidth; }
set {
this.fadewidth = value;
FireChange();
}
}
/// <summary></summary>
[Category("Appearance"), Description("Gets or sets color to gloss"), Browsable(true)]
public Color Color {
get { return this.color; }
set {
this.color = value;
this.topColor = Color.FromArgb(highAlpha, this.color.R, this.color.G, this.color.B);
this.botColor = Color.FromArgb(lowAlpha, this.color.R, this.color.G, this.color.B);
box = new Rectangle(0, 0, 1, 1);
FireChange();
}
}
protected override void PaintThisGloss(Rectangle box, Graphics g) {
if (!this.box.Equals(box)) {
this.box = box;
ResetBrushes(box);
}
//int midpoint = (int)((float)box.Height / 2f);
//int toppoint = midpoint > (fadewidth + 2) ? midpoint - (fadewidth / 2) : midpoint;
//int botpoint = midpoint > (fadewidth + 2) ? midpoint + (fadewidth / 2) : midpoint;
//Rectangle topBox = new Rectangle(box.X, box.Y, box.Width - 1, box.Y + fadewidth);
//Rectangle botBox = new Rectangle(box.X, box.Bottom - fadewidth - 2, box.Width - 1, fadewidth + 1);
Rectangle topBox = new Rectangle(box.X, box.Y, box.Width, fadewidth);
Rectangle botBox = new Rectangle(box.X, box.Bottom - fadewidth, box.Width, fadewidth);
//if (midpoint - fadewidth > 2) { midpoint -= fadewidth; }
switch (style) {
case GlossStyle.Bottom:
g.FillRectangle(lowBrush, botBox);
break;
case GlossStyle.Top:
g.FillRectangle(highBrush, topBox);
break;
case GlossStyle.Both:
g.FillRectangle(highBrush, topBox);
g.FillRectangle(lowBrush, botBox);
//g.DrawRectangle(Pens.Red, topBox);
//g.DrawRectangle(Pens.Blue, botBox);
break;
}
//g.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(64, 255, 0, 0))), topBox);
//g.FillRectangle(new SolidBrush(Color.FromArgb(32, 255, 0, 0)), topBox);
//g.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(64, 0, 0, 255))), botBox);
//g.FillRectangle(new SolidBrush(Color.FromArgb(32, 0, 0, 255)), botBox);
}
protected override void ResizeThis(Rectangle box) {
if (!this.box.Equals(box)) {
this.box = box;
ResetBrushes(box);
}
}
private void ResetBrushes(Rectangle box) {
//int midpoint = (int)((float)box.Height / 2f);
//int toppoint = midpoint - (fadewidth / 2);
//if (toppoint < box.Y + 2) { toppoint = box.Y + 2; }
//int botpoint = midpoint + (fadewidth / 2);
//if (botpoint > box.Height - 2) { botpoint = box.Height - 2; }
//Point top = new Point(box.X, box.Y);
//Point topmid = new Point(box.X, box.Y + fadewidth + 1);
//Point botmid = new Point(box.X, box.Height - fadewidth - 1);
//Point bot = new Point(box.X, box.Bottom);
Rectangle topBox = new Rectangle(box.X, box.Y, box.Width, fadewidth);
Rectangle botBox = new Rectangle(box.X, box.Bottom - fadewidth, box.Width, fadewidth);
Point top = new Point(box.X, topBox.Top);
Point topmid = new Point(box.X, topBox.Bottom);
Point botmid = new Point(box.X, botBox.Top - 1);
Point bot = new Point(box.X, botBox.Bottom);
Color high = topColor;
Color low = botColor;
switch (style) {
case GlossStyle.Top:
highBrush = new LinearGradientBrush(top, topmid, high, low);
break;
case GlossStyle.Bottom:
lowBrush = new LinearGradientBrush(botmid, bot, low, high);
break;
case GlossStyle.Both:
highBrush = new LinearGradientBrush(top, topmid, high, low);
lowBrush = new LinearGradientBrush(botmid, bot, low, high);
break;
}
}
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
if (highBrush != null) { highBrush.Dispose(); }
if (lowBrush != null) { lowBrush.Dispose(); }
}
}
}