-
Notifications
You must be signed in to change notification settings - Fork 5
/
FlatGlossPainter.cs
107 lines (96 loc) · 2.85 KB
/
FlatGlossPainter.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
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.FlatGlossPainter), "Icons.FlatGlossPainter.ico")]
public class FlatGlossPainter : ChainedGlossPainter {
private GlossStyle style = GlossStyle.Bottom;
private int percent = 50;
private Rectangle box;
private Color color = Color.White;
private int alpha = 128;
private Brush brush;
/// <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("Appearance"), Description("Gets or sets the percentage of surface this gloss should cover"), Browsable(true)]
public int PercentageCovered {
get { return this.percent; }
set {
if (value < 0 || value > 100) {
throw new ArgumentException("Percentage value must be between 0 and 100.");
}
this.percent = 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;
box = new Rectangle(0, 0, 1, 1);
FireChange();
}
}
/// <summary></summary>
[Category("Blending"), Description("Gets or sets the alpha value"), Browsable(true)]
public int Alpha {
get { return this.alpha; }
set {
if (value < 0 || value > 255) {
throw new ArgumentException("Alpha values must be between 0 and 255.");
}
this.alpha = value;
box = new Rectangle(0, 0, 1, 1);
FireChange();
}
}
protected override void PaintThisGloss(Rectangle box, Graphics g) {
if (!this.box.Equals(box)) {
this.box = box;
}
int y = (int)(((float)box.Height * (float)percent) / 100f);
if (box.Y + y > box.Height) { y = box.Height; }
Rectangle cover = box;
switch (style) {
case GlossStyle.Bottom:
int start = box.Height + box.Y - y;
cover = new Rectangle(box.X, start, box.Width, box.Bottom - start);
break;
case GlossStyle.Top:
cover = new Rectangle(box.X, box.Y, box.Width, y + 1);
break;
case GlossStyle.Both:
cover = box;
break;
}
Color ccv = Color.FromArgb(alpha, color.R, color.G, color.B);
brush = new SolidBrush(ccv);
g.FillRectangle(brush, cover);
}
protected override void ResizeThis(Rectangle box) {
if (!this.box.Equals(box)) {
this.box = box;
}
}
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
if (brush != null) { brush.Dispose(); }
}
}
}