forked from thezerothcat/LMRItemTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrackerBox.cs
152 lines (135 loc) · 4.64 KB
/
TrackerBox.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
using System;
namespace LMRItemTracker
{
class TrackerBox : System.Windows.Forms.PictureBox
{
public bool Collected { get; set; }
public bool ForeCollected { get; set; }
public bool RedrawOnStateChange { get; set; }
public System.Drawing.Image CollectedImage { get; set; }
public System.Drawing.Image ShadedImage { get; set; }
public System.Drawing.Image SolidImage { get; set; }
public System.Drawing.Image ForeImage { get; set; }
public TrackerBox()
{
Collected = false;
ForeCollected = false;
CollectedImage = null;
ShadedImage = null;
SolidImage = null;
ForeImage = null;
Paint += new System.Windows.Forms.PaintEventHandler(HandlePaint);
}
public void ToggleState(bool isCollected)
{
Collected = isCollected;
if(RedrawOnStateChange)
{
Redraw();
}
}
public void ToggleForeState(bool isCollected)
{
ForeCollected = isCollected;
if (RedrawOnStateChange)
{
Redraw();
}
}
public void Redraw()
{
if (InvokeRequired)
{
Invoke(new Action(() =>
{
DetermineImage();
Refresh();
}));
}
else
{
DetermineImage();
Refresh();
}
}
private void DetermineImage()
{
if (Collected)
{
BackgroundImage = CollectedImage;
}
else
{
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;
}
}
if ("solid".Equals(Properties.Settings.Default.BackgroundMode))
{
Image = Collected && ForeCollected ? ForeImage : null;
}
else
{
Image = ForeCollected ? ForeImage : null;
}
Visible = !"hide".Equals(Properties.Settings.Default.BackgroundMode) || Collected || ForeCollected;
}
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)
{
if (!Collected && "solid".Equals(Properties.Settings.Default.BackgroundMode) && SolidImage != null && !LaMulanaItemTrackerForm.DialogOpen)
{
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);
Image = null;
if (ForeCollected && ForeImage != null)
{
e.Graphics.DrawImage(ForeImage, new System.Drawing.Point(0, 0));
}
}
}
}
}