-
Notifications
You must be signed in to change notification settings - Fork 5
/
MultiStateTrackerBox.cs
142 lines (128 loc) · 4.35 KB
/
MultiStateTrackerBox.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
using System;
namespace LMRItemTracker
{
class MultiStateTrackerBox : System.Windows.Forms.PictureBox
{
public System.Drawing.Bitmap[] CollectedImages { get; set; }
public System.Drawing.Image ShadedImage { get; set; }
public System.Drawing.Image SolidImage { get; set; }
private bool[] Collected;
public MultiStateTrackerBox()
{
Collected = null;
CollectedImages = null;
ShadedImage = null;
SolidImage = null;
Paint += new System.Windows.Forms.PaintEventHandler(HandlePaint);
}
public void ToggleState(bool isCollected, int index)
{
if(Collected == null)
{
Collected = new bool[CollectedImages.Length];
}
Collected[index] = isCollected;
Redraw();
}
private void DetermineImage()
{
bool collectedAny = false;
for (int i = 0; i < Collected.Length; i++)
{
if(Collected[i])
{
BackgroundImage = CollectedImages[i];
collectedAny = true;
break;
}
}
if (!collectedAny)
{
string mode = Properties.Settings.Default.BackgroundMode;
if ("shaded".Equals(mode))
{
BackgroundImage = ShadedImage;
}
else if ("solid".Equals(mode))
{
if (SolidImage == null)
{
BackgroundImage = ShadedImage;
}
else
{
BackgroundImage = SolidImage;
}
}
else
{
BackgroundImage = null;
}
}
Visible = !"hide".Equals(Properties.Settings.Default.BackgroundMode) || collectedAny;
}
public void Redraw()
{
if (InvokeRequired)
{
Invoke(new System.Action(() =>
{
DetermineImage();
Refresh();
}));
}
else
{
DetermineImage();
Refresh();
}
}
private void HandlePaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (InvokeRequired)
{
Invoke(new Action(() =>
{
UpdateImage(e);
}));
}
else
{
UpdateImage(e);
}
}
private void UpdateImage(System.Windows.Forms.PaintEventArgs e)
{
bool collectedAny = false;
if(Collected != null)
{
for (int i = 0; i < Collected.Length; i++)
{
if (Collected[i])
{
collectedAny = true;
break;
}
}
}
if (!collectedAny && "solid".Equals(Properties.Settings.Default.BackgroundMode) && SolidImage != null)
{
e.Graphics.Clear(Properties.Settings.Default.BackgroundColor);
System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(
new float[][]{
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {Properties.Settings.Default.ItemColor.R / 255.0f,
Properties.Settings.Default.ItemColor.G / 255.0f,
Properties.Settings.Default.ItemColor.B / 255.0f,
0, 1}
});
imageAttributes.SetColorMatrix(colorMatrix);
e.Graphics.DrawImage(SolidImage, new System.Drawing.Rectangle(0, 0, 40, 40), 0, 0, 40, 40, System.Drawing.GraphicsUnit.Pixel, imageAttributes);
}
}
}
}