forked from daPhie79/ProgressODoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMiddleGlossPainter.cs
162 lines (150 loc) · 5.34 KB
/
MiddleGlossPainter.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
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Collections.Generic;
namespace ProgressODoom {
/// <summary></summary>
[ToolboxBitmapAttribute(typeof(ProgressODoom.MiddleGlossPainter), "Icons.MiddleGlossPainter.ico")]
public class MiddleGlossPainter : 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 Brush bothBrush;
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;
this.box = new Rectangle(0, 0, 1, 1);
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;
this.box = new Rectangle(0, 0, 1, 1);
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;
this.box = new Rectangle(0, 0, 1, 1);
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;
this.box = new Rectangle(0, 0, 1, 1);
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 = box.X + (int)((float)box.Height / 2f);
Rectangle topBox = new Rectangle(box.X, midpoint - fadewidth, box.Width - 1, fadewidth);
Rectangle botBox = new Rectangle(box.X, midpoint, box.Width - 1, fadewidth);
Rectangle fullBox = new Rectangle(box.X, midpoint - fadewidth, box.Width - 1, fadewidth * 2);
switch (style) {
case GlossStyle.Bottom:
g.FillRectangle(lowBrush, botBox);
//g.DrawRectangle(Pens.Fuchsia, botBox);
break;
case GlossStyle.Top:
g.FillRectangle(highBrush, topBox);
//g.DrawRectangle(Pens.Fuchsia, topBox);
break;
case GlossStyle.Both:
//g.FillRectangle(highBrush, topBox);
//g.FillRectangle(lowBrush, botBox);
g.FillRectangle(bothBrush, fullBox);
break;
}
//g.DrawRectangle(Pens.Purple, fullBox);
//g.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(64, 255, 255, 0))), topBox);
//g.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(64, 0, 255, 0))), botBox);
}
protected override void ResizeThis(Rectangle box) {
if (!this.box.Equals(box)) {
this.box = box;
ResetBrushes(box);
}
}
private void ResetBrushes(Rectangle box) {
int midpoint = box.X + (int)((float)box.Height / 2f);
Rectangle topBox = new Rectangle(box.X, midpoint - fadewidth, box.Width - 1, fadewidth);
Rectangle botBox = new Rectangle(box.X, midpoint, box.Width - 1, fadewidth);
Rectangle fullBox = new Rectangle(box.X, midpoint - fadewidth, box.Width - 1, fadewidth * 2);
//int midpoint = box.X + (int)((float)box.Height / 2f);
Point top = new Point(box.X, fullBox.Top);
Point topmid = new Point(box.X, topBox.Bottom);
Point botmid = new Point(box.X, botBox.Top);
Point bot = new Point(box.X, botBox.Bottom);
Color high = topColor;
Color low = botColor;
//Rectangle fullBox = new Rectangle(box.X, midpoint - fadewidth, box.Width - 1, fadewidth * 2);
switch (style) {
case GlossStyle.Top:
highBrush = new LinearGradientBrush(top, topmid, low, high);
break;
case GlossStyle.Bottom:
lowBrush = new LinearGradientBrush(botmid, bot, high, low);
break;
case GlossStyle.Both:
//highBrush = new LinearGradientBrush(top, topmid, low, high);
//lowBrush = new LinearGradientBrush(botmid, bot, high, low);
bothBrush = new LinearGradientBrush(fullBox, low, high, LinearGradientMode.Vertical);
//((LinearGradientBrush)bothBrush).SetSigmaBellShape(0.5f, 0.5f);
((LinearGradientBrush)bothBrush).SetBlendTriangularShape(0.5f);
break;
}
}
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
if (highBrush != null) { highBrush.Dispose(); }
if (lowBrush != null) { lowBrush.Dispose(); }
if (bothBrush != null) { bothBrush.Dispose(); }
}
}
}