forked from daPhie79/ProgressODoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDualProgressBar.cs
159 lines (146 loc) · 5.29 KB
/
DualProgressBar.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
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
namespace ProgressODoom {
/// <summary></summary>
[ToolboxBitmapAttribute(typeof(ProgressODoom.DualProgressBar), "Icons.DualProgressBar.ico")]
public class DualProgressBar : ProgressBarEx {
private int masterval = 0;
private int mastermax = 100;
private IProgressPainter masterpainter;
private bool masterBottom = false;
private Rectangle masterbox;
private int padding = 0;
protected EventHandler OnMasterValueChanged;
/// <summary></summary>
public event EventHandler MasterValueChanged {
add {
if (OnMasterValueChanged != null) {
foreach (Delegate d in OnMasterValueChanged.GetInvocationList()) {
if (object.ReferenceEquals(d, value)) { return; }
}
}
OnMasterValueChanged = (EventHandler)Delegate.Combine(OnMasterValueChanged, value);
}
remove { OnMasterValueChanged = (EventHandler)Delegate.Remove(OnMasterValueChanged, value); }
}
/// <summary></summary>
[Category("Progress"), Description("Gets or sets the maximum value"), Browsable(true)]
public override int Maximum {
get { return base.maximum; }
set {
base.Maximum = value;
mastermax = value;
}
}
/// <summary></summary>
[Category("Progress"), Description("Gets or sets the value of the master progress"), Browsable(true)]
public int MasterValue {
get { return this.masterval; }
set {
this.masterval = value;
if (OnMasterValueChanged != null) {
OnMasterValueChanged(this, EventArgs.Empty);
}
ResizeMasterProgress();
this.Invalidate();
}
}
/// <summary></summary>
[Category("Progress"), Description("Gets or sets the maximum value for the master progress"), Browsable(true)]
public int MasterMaximum {
get { return mastermax; }
set {
this.mastermax = value;
ResizeMasterProgress();
this.Invalidate();
}
}
/// <summary></summary>
[Category("Progress"), Description("Gets or sets the padding for the master progress"), Browsable(true)]
public int MasterProgressPadding {
get { return this.padding; }
set {
this.padding = value;
if (OnValueChanged != null) {
OnValueChanged(this, EventArgs.Empty);
}
ResizeMasterProgress();
this.Invalidate();
}
}
/// <summary></summary>
[Category("Painters"), Description("Paints this progress bar's master progress"), Browsable(true)]
public IProgressPainter MasterPainter {
get { return this.masterpainter; }
set {
this.masterpainter = value;
if (this.masterpainter is AbstractProgressPainter) {
((AbstractProgressPainter)this.masterpainter).padding = base.ProgressPadding;
}
this.masterpainter.PropertiesChanged += new EventHandler(component_PropertiesChanged);
this.Invalidate();
}
}
/// <summary></summary>
[Category("Progress"), Description("Determines whether or not the master progress is painted under the main progress"), Browsable(true)]
public bool PaintMasterFirst {
get { return this.masterBottom; }
set {
this.masterBottom = value;
this.Invalidate();
}
}
protected override void OnResize(EventArgs e) {
base.OnResize(e);
ResizeProgress();
ResizeMasterProgress();
if (this.backgroundpainter != null) { this.backgroundpainter.Resize(borderbox); }
if (masterBottom && this.masterpainter != null) { this.masterpainter.Resize(masterbox); }
if (this.progresspainter != null) { this.progresspainter.Resize(borderbox); }
if (!masterBottom && this.masterpainter != null) { this.masterpainter.Resize(masterbox); }
if (this.borderpainter != null) { this.borderpainter.Resize(borderbox); }
}
private void ResizeMasterProgress() {
Rectangle newprog = base.borderbox;
newprog.Offset(this.borderpainter.BorderWidth, this.borderpainter.BorderWidth);
newprog.Size = new Size(newprog.Size.Width - this.borderpainter.BorderWidth, newprog.Size.Height - this.borderpainter.BorderWidth);
base.backbox = newprog;
int val = masterval; if (val > 0) { val++; }
int progWidth = mastermax > 0 ? (backbox.Width * val / mastermax) : 1;
if (value >= mastermax && mastermax > 0) {
progWidth = backbox.Width;
} /*else if (value > 0) {
progWidth++;
}*/
//newprog = new Rectangle(backbox.X + base.ProgressPadding, backbox.Y + base.ProgressPadding, progWidth - (base.ProgressPadding * 2), backbox.Height - (base.ProgressPadding * 2));
//newprog = new Rectangle(backbox.X, backbox.Y, progWidth, backbox.Height);
newprog = new Rectangle(backbox.X + this.padding, backbox.Y + this.padding, progWidth - (this.padding * 2), backbox.Height - (this.padding * 2));
masterbox = newprog;
}
///// <summary></summary>
//protected override void MarqueeStart() {
//}
///// <summary></summary>
//protected override void MarqueePause() {
//}
///// <summary></summary>
//protected override void MarqueeStop() {
//}
/// <summary></summary>
/// <param name="gr"></param>
protected override void PaintProgress(Graphics g) {
if (this.progresspainter != null) {
if (masterBottom && this.masterpainter != null) {
this.masterpainter.PaintProgress(masterbox, g);
}
this.progresspainter.PaintProgress(progressbox, g);
if (!masterBottom && this.masterpainter != null) {
this.masterpainter.PaintProgress(masterbox, g);
}
}
}
}
}