forked from daPhie79/ProgressODoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChainedGlossPainter.cs
84 lines (74 loc) · 2.61 KB
/
ChainedGlossPainter.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
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Collections.Generic;
namespace ProgressODoom {
/// <summary>Extending this class allows you to chain multiple IGlossPainters together.</summary>
public abstract class ChainedGlossPainter : Component, IGlossPainter, IDisposable {
private IGlossPainter successor = null;
/// <summary></summary>
[Category("Painters"), Description("Gets or sets the next gloss in the chain"), Browsable(true)]
public IGlossPainter Successor {
get { return successor; }
set {
IGlossPainter nextPainter = value;
while (nextPainter != null && nextPainter is ChainedGlossPainter) {
if (object.ReferenceEquals(this, nextPainter)) {
throw new ArgumentException("Gloss cannot eventually be it's own successor, an infinite loop will result");
}
nextPainter = ((ChainedGlossPainter)nextPainter).Successor;
}
successor = value;
if (successor != null) {
successor.PropertiesChanged += new EventHandler(successor_PropertiesChanged);
}
FireChange();
}
}
private void successor_PropertiesChanged(object sender, EventArgs e) {
FireChange();
}
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); }
}
/// <summary></summary>
protected void FireChange() {
if (onPropertiesChanged != null) { onPropertiesChanged(this, EventArgs.Empty); }
}
/// <summary></summary>
/// <param name="box"></param>
/// <param name="g"></param>
public void PaintGloss(Rectangle box, Graphics g) {
if (box.Width < 1) { return; }
PaintThisGloss(box, g);
if (successor != null) { successor.PaintGloss(box, g); }
}
/// <summary></summary>
/// <param name="box"></param>
/// <param name="g"></param>
protected abstract void PaintThisGloss(Rectangle box, Graphics g);
/// <summary></summary>
/// <param name="box"></param>
public void Resize(Rectangle box) {
ResizeThis(box);
if (successor != null) { successor.Resize(box); }
}
protected abstract void ResizeThis(Rectangle box);
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
if (successor != null) { successor.Dispose(); }
}
}
}